Skip to content
Myr

fix issue routing requests among sub routers

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

fixes #2121

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 097cd0c · Browse files · 3 files+45 added−3 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+45 added−3 removed

  • tests:+37 added−0 removed
  • other:+8 added−3 removed

3 files+45 added−3 removed

modified:lib/router/index.js+7 added-3 removed
154 unmodified lines
155 err = undefined;156 }157158 var layer = stack[idx++];159 var layerPath;160161 if (!layer) {162 return done(err);163 }164
29 unmodified lines
194 options.push.apply(options, route._options());195 }196 }197198 // Capture one-time layer values199 req.params = layer.params;200 layerPath = layer.path;201202 // this should be done for the layer203 return self.process_params(layer, req, res, function(err) {204 if (err) {
11 unmodified lines
216 next(err);217 }218219 function trim_prefix() {216 var c = path[layer.path.length];220 var c = path[layerPath.length];221 if (c && '/' != c && '.' != c) return next(err);222223 // Trim off the part of the url that matches the route224 // middleware (.use stuff) needs to have the path stripped225 debug('trim prefix (%s) from url %s', removed, req.url);222 removed = layer.path;226 removed = layerPath;227 req.url = protohost + req.url.substr(protohost.length + removed.length);228229 // Ensure leading slash230 if (!fqdn && '/' != req.url[0]) {231 req.url = '/' + req.url;232 slashAdded = true;233 }234231 debug('%s %s : %s', layer.handle.name || 'anonymous', layer.path, req.originalUrl);235 debug('%s %s : %s', layer.handle.name || 'anonymous', layerPath, req.originalUrl);236 var arity = layer.handle.length;237 if (err) {238 if (arity === 4) {239 layer.handle(err, req, res, next);
166 unmodified lines
modified:test/Router.js+37 added
182 unmodified lines
183184 router.handle({ url: '/foo/123/bar/baz', method: 'get' }, {}, done);185 });186 });187188 describe('parallel requests', function() {189 it('should not mix requests', function(done) {190 var count = 2;191 var req1 = { url: '/foo/50/bar', method: 'get' };192 var req2 = { url: '/foo/10/bar', method: 'get' };193 var router = new Router();194 var sub = new Router();195196 sub.get('/bar', function(req, res, next) {197 next();198 });199200 router.param('ms', function(req, res, next, ms) {201 ms = parseInt(ms, 10);202 req.ms = ms;203 setTimeout(next, ms);204 });205206 router.use('/foo/:ms/', new Router());207 router.use('/foo/:ms/', sub);208209 router.handle(req1, {}, function(err) {210 assert.ifError(err);211 assert.equal(req1.ms, 50);212 assert.equal(req1.originalUrl, '/foo/50/bar');213 if (!--count) done();214 });215216 router.handle(req2, {}, function(err) {217 assert.ifError(err);218 assert.equal(req2.ms, 10);219 assert.equal(req2.originalUrl, '/foo/10/bar');220 if (!--count) done();221 });222 });223 });224})
modified:History.md+1 added
1unreleased2==========34 * fix behavior of multiple `app.VERB` for the same path5 * fix issue routing requests among sub routers6 * proper proxy trust with `app.set('trust proxy', trust)`7 - `app.set('trust proxy', 1)` trust first hop8 - `app.set('trust proxy', 'loopback')` trust loopback addresses9 - `app.set('trust proxy', '10.0.0.1')` trust single IP
1442 unmodified lines