mirror of
https://github.com/expressjs/express.git
synced 2026-02-26 17:35:03 +00:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45faee3e5b | ||
|
|
74ff735e10 | ||
|
|
97879f2b16 | ||
|
|
1a338251ad | ||
|
|
354dc768c1 | ||
|
|
8a0796cd94 | ||
|
|
cbc3b26584 | ||
|
|
d628583db8 | ||
|
|
058777be1e | ||
|
|
260d03a0c4 | ||
|
|
6dcf6f41cc | ||
|
|
799f790886 | ||
|
|
cb3c4b0ea9 | ||
|
|
798d255ba6 | ||
|
|
28ba9e8ac5 | ||
|
|
7888cb0506 | ||
|
|
5e284a20cc | ||
|
|
770357e727 | ||
|
|
673ba22555 | ||
|
|
fb38d9cfb7 | ||
|
|
dda89a57ec | ||
|
|
62df63d3a0 | ||
|
|
e71696cf34 | ||
|
|
b5d8d58670 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,5 +6,7 @@ lib-cov
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.swp
|
||||
*.swo
|
||||
benchmarks/graphs
|
||||
testing.js
|
||||
|
||||
15
History.md
15
History.md
@@ -1,4 +1,19 @@
|
||||
|
||||
2.2.0 / 2011-03-30
|
||||
==================
|
||||
|
||||
* Added `app.lookup.VERB()`, ex `app.lookup.put('/user/:id')`. Closes #606
|
||||
* Added `app.match.VERB()`, ex `app.match.put('/user/12')`. Closes #606
|
||||
* Added `app.VERB(path)` as alias of `app.lookup.VERB()`.
|
||||
* Dependency `connect >= 1.1.6`
|
||||
|
||||
2.1.1 / 2011-03-29
|
||||
==================
|
||||
|
||||
* Added; expose `err.view` object when failing to locate a view
|
||||
* Fixed `res.partial()` call `next(err)` when no callback is given [reported by aheckmann]
|
||||
* Fixed; `res.send(undefined)` responds with 204 [aheckmann]
|
||||
|
||||
2.1.0 / 2011-03-24
|
||||
==================
|
||||
|
||||
|
||||
16
bin/express
16
bin/express
@@ -11,7 +11,7 @@ var fs = require('fs')
|
||||
* Framework version.
|
||||
*/
|
||||
|
||||
var version = '2.1.0';
|
||||
var version = '2.2.0';
|
||||
|
||||
/**
|
||||
* Add session support.
|
||||
@@ -37,14 +37,14 @@ var templateEngine = 'jade';
|
||||
|
||||
var usage = ''
|
||||
+ '\n'
|
||||
+ ' \x1b[1mUsage\x1b[0m: express [options] [PATH]\n'
|
||||
+ ' Usage: express [options] [path]\n'
|
||||
+ '\n'
|
||||
+ ' \x1b[1mOptions\x1b[0m:\n'
|
||||
+ ' -s, --sessions Add session support\n'
|
||||
+ ' -t, --template ENGINE Add template ENGINE support (jade|ejs). Defaults to jade\n'
|
||||
+ ' -c, --css ENGINE Add stylesheet ENGINE support (less|sass|stylus). Defaults to plain css\n'
|
||||
+ ' -v, --version Output framework version\n'
|
||||
+ ' -h, --help Output help information\n'
|
||||
+ ' Options:\n'
|
||||
+ ' -s, --sessions add session support\n'
|
||||
+ ' -t, --template <engine> add template <engine> support (jade|ejs). default=jade\n'
|
||||
+ ' -c, --css <engine> add stylesheet <engine> support (less|sass|stylus). default=plain css\n'
|
||||
+ ' -v, --version output framework version\n'
|
||||
+ ' -h, --help output help information\n'
|
||||
;
|
||||
|
||||
/**
|
||||
|
||||
@@ -878,7 +878,7 @@ The _maxAge_ property may be used to set _expires_ relative to _Date.now()_ in m
|
||||
|
||||
res.cookie('rememberme', 'yes', { maxAge: 900000 });
|
||||
|
||||
To parse incoming _Cookie_ headers, use the _cookieDecoder_ middleware, which provides the _req.cookies_ object:
|
||||
To parse incoming _Cookie_ headers, use the _cookieParser_ middleware, which provides the _req.cookies_ object:
|
||||
|
||||
app.use(express.cookieParser());
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ var exports = module.exports = connect.middleware;
|
||||
* Framework version.
|
||||
*/
|
||||
|
||||
exports.version = '2.1.0';
|
||||
exports.version = '2.2.0';
|
||||
|
||||
/**
|
||||
* Shortcut for `new Server(...)`.
|
||||
|
||||
24
lib/http.js
24
lib/http.js
@@ -44,6 +44,8 @@ Server.prototype.__proto__ = connect.HTTPServer.prototype;
|
||||
|
||||
Server.prototype.init = function(middleware){
|
||||
var self = this;
|
||||
this.match = {};
|
||||
this.lookup = {};
|
||||
this.settings = {};
|
||||
this.redirects = {};
|
||||
this.isCallbacks = {};
|
||||
@@ -108,6 +110,21 @@ Server.prototype.init = function(middleware){
|
||||
// register error handlers on "listening"
|
||||
// so that they disregard definition position.
|
||||
this.on('listening', this.registerErrorHandlers.bind(this));
|
||||
|
||||
// route lookup methods
|
||||
methods.forEach(function(method){
|
||||
self.match[method] = function(url){
|
||||
return self.router.match(url, 'all' == method
|
||||
? null
|
||||
: method);
|
||||
};
|
||||
|
||||
self.lookup[method] = function(path){
|
||||
return self.router.lookup(path, 'all' == method
|
||||
? null
|
||||
: method);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -442,6 +459,13 @@ function generateMethod(method){
|
||||
Server.prototype[method] = function(path, fn){
|
||||
var self = this;
|
||||
|
||||
// Lookup
|
||||
if (1 == arguments.length) {
|
||||
return this.router.lookup(path, 'all' == method
|
||||
? null
|
||||
: method);
|
||||
}
|
||||
|
||||
// Ensure router is mounted
|
||||
if (!this.__usedRouter) {
|
||||
this.use(this.router);
|
||||
|
||||
@@ -51,7 +51,7 @@ res.send = function(body, headers, status){
|
||||
status = status || this.statusCode;
|
||||
|
||||
// allow 0 args as 204
|
||||
if (!arguments.length) body = status = 204;
|
||||
if (!arguments.length || undefined === body) body = status = 204;
|
||||
|
||||
// determine content type
|
||||
switch (typeof body) {
|
||||
|
||||
10
lib/view.js
10
lib/view.js
@@ -179,8 +179,9 @@ res.partial = function(view, options, fn){
|
||||
if (fn) {
|
||||
fn(err);
|
||||
} else {
|
||||
throw err;
|
||||
this.req.next(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// callback or transfer
|
||||
@@ -220,7 +221,8 @@ res.render = function(view, opts, fn, parent, sub){
|
||||
// callback given
|
||||
if (fn) {
|
||||
fn(err);
|
||||
// unwind to root call
|
||||
// unwind to root call to prevent
|
||||
// several next(err) calls
|
||||
} else if (sub) {
|
||||
throw err;
|
||||
// root template, next(err)
|
||||
@@ -304,7 +306,9 @@ res._render = function(view, opts, fn, parent, sub){
|
||||
// Does not exist
|
||||
if (!view.exists) {
|
||||
if (app.enabled('hints')) hintAtViewPaths(orig, options);
|
||||
throw new Error('failed to locate view "' + orig.view + '"');
|
||||
var err = new Error('failed to locate view "' + orig.view + '"');
|
||||
err.view = orig;
|
||||
throw err;
|
||||
}
|
||||
|
||||
// Dynamic helper support
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "express",
|
||||
"description": "Sinatra inspired web development framework",
|
||||
"version": "2.1.0",
|
||||
"version": "2.2.0",
|
||||
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
||||
"contributors": [
|
||||
{ "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" },
|
||||
@@ -10,11 +10,12 @@
|
||||
{ "name": "Guillermo Rauch", "email": "rauchg@gmail.com" }
|
||||
],
|
||||
"dependencies": {
|
||||
"connect": ">= 1.1.1 < 2.0.0",
|
||||
"connect": ">= 1.1.6 < 2.0.0",
|
||||
"mime": ">= 0.0.1",
|
||||
"qs": ">= 0.0.6"
|
||||
},
|
||||
"keywords": ["framework", "sinatra", "web", "rest", "restful"],
|
||||
"repository": "git://github.com/visionmedia/express",
|
||||
"main": "index",
|
||||
"bin": { "express": "./bin/express" },
|
||||
"engines": { "node": ">= 0.4.1 < 0.5.0" }
|
||||
|
||||
Submodule support/connect updated: 2b3cea7744...b8e5d9c28e
Submodule support/connect-form updated: ccefcd28db...e861cc85d6
Submodule support/ejs updated: 673e6f23cb...499c4815a5
Submodule support/expresso updated: 2c8759f147...855e0dea07
Submodule support/formidable updated: 63347d825b...5d98e9c75c
Submodule support/haml updated: 4122210f38...55bb6fdc79
Submodule support/jade updated: 1e23782b6f...9ec358e0f1
@@ -561,5 +561,47 @@ module.exports = {
|
||||
assert.response(app,
|
||||
{ url: '/user/12', method: 'OPTIONS' },
|
||||
{ headers: { Allow: 'GET,PUT' }});
|
||||
},
|
||||
|
||||
'test app.lookup': function(){
|
||||
var app = express.createServer();
|
||||
app.get('/user', function(){});
|
||||
app.get('/user/:id', function(){});
|
||||
app.get('/user/:id/:op?', function(){});
|
||||
app.put('/user/:id', function(){});
|
||||
app.get('/user/:id/edit', function(){});
|
||||
|
||||
app.get('/user').should.have.length(1);
|
||||
app.get('/user/:id').should.have.length(1);
|
||||
app.get('/user/:id/:op?').should.have.length(1);
|
||||
app.put('/user/:id').should.have.length(1);
|
||||
app.get('/user/:id/edit').should.have.length(1);
|
||||
app.get('/').should.have.be.empty;
|
||||
app.all('/user/:id').should.have.length(2);
|
||||
|
||||
app.lookup.get('/user').should.have.length(1);
|
||||
app.lookup.get('/user/:id').should.have.length(1);
|
||||
app.lookup.get('/user/:id/:op?').should.have.length(1);
|
||||
app.lookup.put('/user/:id').should.have.length(1);
|
||||
app.lookup.get('/user/:id/edit').should.have.length(1);
|
||||
app.lookup.get('/').should.have.be.empty;
|
||||
app.lookup.all('/user/:id').should.have.length(2);
|
||||
},
|
||||
|
||||
'test app.match': function(){
|
||||
var app = express.createServer();
|
||||
app.get('/user', function(){});
|
||||
app.get('/user/:id', function(){});
|
||||
app.get('/user/:id/:op?', function(){});
|
||||
app.put('/user/:id', function(){});
|
||||
app.get('/user/:id/edit', function(){});
|
||||
|
||||
app.match.get('/user').should.have.length(1);
|
||||
app.match.get('/user/12').should.have.length(2);
|
||||
app.match.get('/user/12/:op?').should.have.length(1);
|
||||
app.match.put('/user/100').should.have.length(1);
|
||||
app.match.get('/user/5/edit').should.have.length(2);
|
||||
app.match.get('/').should.have.be.empty;
|
||||
app.match.all('/user/123').should.have.length(3);
|
||||
}
|
||||
};
|
||||
|
||||
1
test/fixtures/error.jade
vendored
Normal file
1
test/fixtures/error.jade
vendored
Normal file
@@ -0,0 +1 @@
|
||||
= user.name
|
||||
@@ -50,6 +50,10 @@ module.exports = {
|
||||
res.send();
|
||||
});
|
||||
|
||||
app.get('/undefined', function(req, res, next){
|
||||
res.send(undefined);
|
||||
});
|
||||
|
||||
app.get('/bool', function(req, res, next){
|
||||
res.send(true);
|
||||
});
|
||||
@@ -148,6 +152,13 @@ module.exports = {
|
||||
assert.equal(undefined, res.headers['content-type']);
|
||||
assert.equal(undefined, res.headers['content-length']);
|
||||
});
|
||||
|
||||
assert.response(app,
|
||||
{ url: '/undefined' },
|
||||
{ status: 204 }, function(res){
|
||||
assert.equal(undefined, res.headers['content-type']);
|
||||
assert.equal(undefined, res.headers['content-length']);
|
||||
});
|
||||
},
|
||||
|
||||
'test #contentType()': function(){
|
||||
|
||||
@@ -619,6 +619,18 @@ module.exports = {
|
||||
assert.response(app,
|
||||
{ url: '/root/underscore' },
|
||||
{ body: '<p>Testing</p>' });
|
||||
|
||||
// error in template
|
||||
|
||||
app.get('/error', function(req, res){
|
||||
process.nextTick(function(){
|
||||
res.partial('error');
|
||||
});
|
||||
});
|
||||
|
||||
assert.response(app,
|
||||
{ url: '/error' },
|
||||
{ status: 500 });
|
||||
},
|
||||
|
||||
'test #partial() with several calls': function(){
|
||||
|
||||
Reference in New Issue
Block a user