Compare commits

...

9 Commits
4.3.0 ... 4.3.2

Author SHA1 Message Date
Douglas Christopher Wilson
311e83e591 4.3.2 2014-05-29 00:17:21 -04:00
Douglas Christopher Wilson
fb2d918056 fix handling of errors from param callbacks
fixes #2149
2014-05-28 22:26:05 -04:00
Douglas Christopher Wilson
dfefea5e9d update example dependencies 2014-05-27 23:51:47 -04:00
Douglas Christopher Wilson
3fbab91231 Merge tag '3.8.1' 2014-05-27 23:49:47 -04:00
Douglas Christopher Wilson
f7e73e2da0 3.8.1 2014-05-27 23:43:13 -04:00
Douglas Christopher Wilson
867728b5ab update connect to 2.17.3 2014-05-27 23:02:27 -04:00
Douglas Christopher Wilson
87e02c30e7 4.3.1 2014-05-23 19:11:28 -04:00
Douglas Christopher Wilson
c3470c9c96 tests: add route ordering test 2014-05-23 18:46:00 -04:00
Douglas Christopher Wilson
7f049164b7 Revert "fix behavior of multiple app.VERB for the same path"
This reverts commit 31b2e2d7b4.

fixes #2133
2014-05-23 18:35:20 -04:00
7 changed files with 109 additions and 63 deletions

View File

@@ -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
==================

View File

@@ -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;
};

View File

@@ -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);

View File

@@ -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"
},

View File

@@ -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(){

View File

@@ -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);
})
})
})

View File

@@ -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);