mirror of
https://github.com/expressjs/express.git
synced 2026-02-27 03:07:33 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
311e83e591 | ||
|
|
fb2d918056 | ||
|
|
dfefea5e9d | ||
|
|
3fbab91231 | ||
|
|
f7e73e2da0 | ||
|
|
867728b5ab | ||
|
|
87e02c30e7 | ||
|
|
c3470c9c96 | ||
|
|
7f049164b7 |
19
History.md
19
History.md
@@ -1,3 +1,14 @@
|
||||
4.3.2 / 2014-05-28
|
||||
==================
|
||||
|
||||
* fix handling of errors from `router.param()` callbacks
|
||||
|
||||
4.3.1 / 2014-05-23
|
||||
==================
|
||||
|
||||
* revert "fix behavior of multiple `app.VERB` for the same path"
|
||||
- this caused a regression in the order of route execution
|
||||
|
||||
4.3.0 / 2014-05-21
|
||||
==================
|
||||
|
||||
@@ -113,6 +124,14 @@
|
||||
- `app.route()` - Proxy to the app's `Router#route()` method to create a new route
|
||||
- Router & Route - public API
|
||||
|
||||
3.8.1 / 2014-05-27
|
||||
==================
|
||||
|
||||
* update connect to 2.17.3
|
||||
- deps: body-parser@1.2.2
|
||||
- deps: express-session@1.2.1
|
||||
- deps: method-override@1.0.2
|
||||
|
||||
3.8.0 / 2014-05-21
|
||||
==================
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ var app = exports = module.exports = {};
|
||||
*/
|
||||
|
||||
app.init = function(){
|
||||
this._baseRoutes = {};
|
||||
this.cache = {};
|
||||
this.settings = {};
|
||||
this.engines = {};
|
||||
@@ -408,11 +407,11 @@ app.disable = function(setting){
|
||||
|
||||
methods.forEach(function(method){
|
||||
app[method] = function(path){
|
||||
if (method === 'get' && arguments.length === 1) {
|
||||
return this.set(path);
|
||||
}
|
||||
if ('get' == method && 1 == arguments.length) return this.set(path);
|
||||
|
||||
var route = this._baseRoute(path);
|
||||
this.lazyrouter();
|
||||
|
||||
var route = this._router.route(path);
|
||||
route[method].apply(route, [].slice.call(arguments, 1));
|
||||
return this;
|
||||
};
|
||||
@@ -429,7 +428,9 @@ methods.forEach(function(method){
|
||||
*/
|
||||
|
||||
app.all = function(path){
|
||||
var route = this._baseRoute(path);
|
||||
this.lazyrouter();
|
||||
|
||||
var route = this._router.route(path);
|
||||
var args = [].slice.call(arguments, 1);
|
||||
methods.forEach(function(method){
|
||||
route[method].apply(route, args);
|
||||
@@ -538,32 +539,3 @@ app.listen = function(){
|
||||
var server = http.createServer(this);
|
||||
return server.listen.apply(server, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get or create a new base route for path.
|
||||
*
|
||||
* @param {String} path
|
||||
* @return {Route}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
app._baseRoute = function(path){
|
||||
this.lazyrouter();
|
||||
|
||||
var key = typeof path !== 'string'
|
||||
? 'o:' + String(path)
|
||||
: 's:' + path;
|
||||
|
||||
if (path.ignoreCase || !this._router.caseSensitive) {
|
||||
key = 'i' + key.toLowerCase();
|
||||
}
|
||||
|
||||
var route = this._baseRoutes[key];
|
||||
|
||||
if (!route) {
|
||||
route = this._router.route(path);
|
||||
this._baseRoutes[key] = route;
|
||||
}
|
||||
|
||||
return route;
|
||||
};
|
||||
|
||||
@@ -290,6 +290,7 @@ proto.process_params = function(layer, called, req, res, done) {
|
||||
var key;
|
||||
var paramVal;
|
||||
var paramCallbacks;
|
||||
var paramCalled;
|
||||
|
||||
// process params in order
|
||||
// param callbacks can be async
|
||||
@@ -312,12 +313,18 @@ proto.process_params = function(layer, called, req, res, done) {
|
||||
name = key.name;
|
||||
paramVal = req.params[name];
|
||||
paramCallbacks = params[name];
|
||||
paramCalled = called[name];
|
||||
|
||||
if (paramVal === undefined || !paramCallbacks || called[name] === paramVal) {
|
||||
if (paramVal === undefined || !paramCallbacks) {
|
||||
return param();
|
||||
}
|
||||
|
||||
called[name] = paramVal;
|
||||
// param previously called with same value or error occurred
|
||||
if (paramCalled && (paramCalled.err || paramCalled.val === paramVal)) {
|
||||
return param(paramCalled.err);
|
||||
}
|
||||
|
||||
called[name] = paramCalled = { val: paramVal };
|
||||
|
||||
try {
|
||||
return paramCallback();
|
||||
@@ -328,6 +335,11 @@ proto.process_params = function(layer, called, req, res, done) {
|
||||
|
||||
// single param callbacks
|
||||
function paramCallback(err) {
|
||||
if (err && paramCalled) {
|
||||
// store error
|
||||
paramCalled.err = err;
|
||||
}
|
||||
|
||||
var fn = paramCallbacks[paramIndex++];
|
||||
if (err || !fn) return param(err);
|
||||
fn(req, res, paramCallback, paramVal, key.name);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "express",
|
||||
"description": "Sinatra inspired web development framework",
|
||||
"version": "4.3.0",
|
||||
"version": "4.3.2",
|
||||
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
||||
"contributors": [
|
||||
{
|
||||
@@ -78,10 +78,10 @@
|
||||
"marked": "0.3.2",
|
||||
"multiparty": "~3.2.4",
|
||||
"hjs": "~0.0.6",
|
||||
"body-parser": "1.2.0",
|
||||
"body-parser": "1.2.2",
|
||||
"cookie-parser": "1.1.0",
|
||||
"express-session": "1.2.0",
|
||||
"method-override": "1.0.1",
|
||||
"express-session": "1.2.1",
|
||||
"method-override": "1.0.2",
|
||||
"morgan": "1.1.1",
|
||||
"vhost": "1.0.0"
|
||||
},
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('HEAD', function(){
|
||||
})
|
||||
|
||||
describe('app.head()', function(){
|
||||
it('should override prior', function(done){
|
||||
it('should override', function(done){
|
||||
var app = express()
|
||||
, called;
|
||||
|
||||
@@ -56,27 +56,6 @@ describe('app.head()', function(){
|
||||
res.send('tobi');
|
||||
});
|
||||
|
||||
request(app)
|
||||
.head('/tobi')
|
||||
.expect(200, function(){
|
||||
assert(called);
|
||||
done();
|
||||
});
|
||||
})
|
||||
it('should override after', function(done){
|
||||
var app = express()
|
||||
, called;
|
||||
|
||||
app.get('/tobi', function(req, res){
|
||||
assert(0, 'should not call GET');
|
||||
res.send('tobi');
|
||||
});
|
||||
|
||||
app.head('/tobi', function(req, res){
|
||||
called = true;
|
||||
res.end('');
|
||||
});
|
||||
|
||||
request(app)
|
||||
.head('/tobi')
|
||||
.expect(200, function(){
|
||||
|
||||
@@ -194,5 +194,30 @@ describe('app', function(){
|
||||
.get('/user/123')
|
||||
.expect('name', done);
|
||||
})
|
||||
|
||||
it('should defer all the param routes', function(done){
|
||||
var app = express();
|
||||
|
||||
app.param('id', function(req, res, next, val){
|
||||
if (val === 'new') return next('route');
|
||||
return next();
|
||||
});
|
||||
|
||||
app.all('/user/:id', function(req, res){
|
||||
res.send('all.id');
|
||||
});
|
||||
|
||||
app.get('/user/:id', function(req, res){
|
||||
res.send('get.id');
|
||||
});
|
||||
|
||||
app.get('/user/new', function(req, res){
|
||||
res.send('get.new');
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/user/new')
|
||||
.expect('get.new', done);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -588,6 +588,45 @@ describe('app.router', function(){
|
||||
.expect('editing user 12', done);
|
||||
})
|
||||
|
||||
it('should run in order added', function(done){
|
||||
var app = express();
|
||||
var path = [];
|
||||
|
||||
app.get('*', function(req, res, next){
|
||||
path.push(0);
|
||||
next();
|
||||
});
|
||||
|
||||
app.get('/user/:id', function(req, res, next){
|
||||
path.push(1);
|
||||
next();
|
||||
});
|
||||
|
||||
app.use(function(req, res, next){
|
||||
path.push(2);
|
||||
next();
|
||||
});
|
||||
|
||||
app.all('/user/:id', function(req, res, next){
|
||||
path.push(3);
|
||||
next();
|
||||
});
|
||||
|
||||
app.get('*', function(req, res, next){
|
||||
path.push(4);
|
||||
next();
|
||||
});
|
||||
|
||||
app.use(function(req, res, next){
|
||||
path.push(5);
|
||||
res.end(path.join(','))
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/user/1')
|
||||
.expect(200, '0,1,2,3,4,5', done);
|
||||
})
|
||||
|
||||
it('should be chainable', function(){
|
||||
var app = express();
|
||||
app.get('/', function(){}).should.equal(app);
|
||||
|
||||
Reference in New Issue
Block a user