Skip to content
Myr

Request#pass() accepts a pathname string

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent f008af0 · Browse files · 3 files+30 added−9 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+30 added−9 removed

  • tests:+17 added−4 removed
  • other:+13 added−5 removed

3 files+30 added−9 removed

modified:lib/express/core.js+5 added-2 removed
103 unmodified lines
104 * @api private105 */106 107 route: function() { 108 var route = this.matchingRoute(), body108 var body, 109 route = this.matchingRoute()110 if (route) {111 body = route.fn.apply(this.request, this.request.captures.slice(1));112 if (this.request.passed) {113 if (typeof this.request.passed === 'string')114 this.request.url.pathname = this.request.passed115 this.request.passed = false116 return this.route()117 }115 return body;118 return body119 }120 else if (this.request.accepts('html') && set('helpful 404'))121 this.request.halt(404, require('express/pages/not-found').render(this.request))122 else
229 unmodified lines
modified:lib/express/request.js+8 added-3 removed
177 unmodified lines
178 });179 },180 181 /**182 * Pass control to the next matching route.182 * Pass control to the next matching route, or183 * the given _path_.184 *185 * NOTE: _path_ may be the request pathname only,186 * and may not contain a query string etc.187 *188 * @param {string} path189 * @api public190 */191 187 pass: function () {188 this.passed = true192 pass: function(path) {193 this.passed = path || true194 return this195 },196 197 /**
90 unmodified lines
modified:spec/spec.request.js+17 added-4 removed
200 unmodified lines
201 end202 203 describe '#pass()'204 it 'should pass control to the next matching route'205 get('/user', function () { 205 get('/user', function(){ 206 this.pass()207 })208 get('/user', function () { 208 get('/user', function(){209 this.pass()210 return 'nodejs'211 })212 get('/user', function () { return 'success'})212 get('/user', function(){ return 'success'})213 get('/user').body.should.eql 'success'214 end215 216 describe 'given a string'217 it 'should pass to the given route'218 get('/user', function(){219 this.pass('/user/1')220 })221 get('/user/:id', function(){222 return 'Supa doopa usa'223 })224 get('/user').body.should.eql 'Supa doopa usa'215 end 225 end226 end227 end228 229 end230end