Merge branch 'pull'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parents c429e88, 3aa870d · Browse files · 3 files·+47 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+47 added−8 removed
- tests:+14 added−0 removed
- other:+33 added−8 removed
Provenance
- Commit
f008af0- Tree
8f51b91- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent 1
c429e88- Parent 2
3aa870d
3 files changed+47 added−8 removed
modified:lib/express/core.js+22 added-8 removed
102 unmodified lines103 * @return {mixed}104 * @api private105 */106 107- route: function(){108- var route = this.matchingRoute()109- if (route)110- return route.fn.apply(this.request, this.request.captures.slice(1))107+ route: function() { 108+ var route = this.matchingRoute(), body109+ if (route) {110+ body = route.fn.apply(this.request, this.request.captures.slice(1));111+ if (this.request.passed) {112+ this.request.passed = false113+ return this.route()114+ }115+ return body;116+ }117 else if (this.request.accepts('html') && set('helpful 404'))118 this.request.halt(404, require('express/pages/not-found').render(this.request))119 else120 this.request.halt()5 unmodified lines126 * @return {Route}127 * @api private128 */129 124- matchingRoute: function(){125- return Express.routes.find(function(route){126- return this.match(route)127- }, this)130+ matchingRoute: function() {131+ // Stop at the first match. If request.pass() was called132+ // continue from where we left off 133+ var i = -1134+ this.matchingRoute = function() {135+ var routes = Express.routes, route136+ while (route = routes[++i]) 137+ if (this.match(route))138+ break139+ return route140+ }141+ return this.matchingRoute() 142 },143 144 /**145 * Check if _route_ matches the current request.203 unmodified linesmodified:lib/express/request.js+11 added
177 unmodified lines178 });179 },180 181 /**182+ * Pass control to the next matching route.183+ *184+ * @api public185+ */186+ 187+ pass: function () {188+ this.passed = true189+ return this190+ },191+ 192+ /**193 * Set Content-Type header to the mime type194 * for the given _path_, which calls mime.type().195 *196 * @param {string} path86 unmodified linesmodified:spec/spec.request.js+14 added
196 unmodified lines197 return [path, file, ext].join(', ')198 })199 get('/public/app.js').body.should.eql 'public, app, js'200 end201+ end202+ 203+ describe '#pass()'204+ it 'should pass control to the next matching route'205+ get('/user', function () { 206+ this.pass()207+ })208+ get('/user', function () { 209+ this.pass()210+ return 'nodejs'211+ })212+ get('/user', function () { return 'success'})213+ get('/user').body.should.eql 'success'214+ end215 end 216 end217 end