Skip to content
Myr

Add next("router") to exit from router

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

closes #2241 closes #2371

authored by Blake Embrey · committed by Douglas Christopher Wilson · parent 51f5290 · Browse files · 4 files+44 added−0 removed
This commit

State

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

Diff stats

4 files+44 added−0 removed

  • tests:+31 added−0 removed
  • other:+13 added−0 removed

4 files+44 added−0 removed

modified:lib/router/index.js+6 added
189 unmodified lines
190 req.url = protohost + removed + req.url.substr(protohost.length);191 removed = '';192 }193194 // signal to exit router195 if (layerError === 'router') {196 setImmediate(done, null)197 return198 }199200 // no more matching layers201 if (idx >= stack.length) {202 setImmediate(done, layerError);203 return;
459 unmodified lines
modified:lib/router/route.js+6 added
110 unmodified lines
111112 next();113114 function next(err) {115 // signal to exit route116 if (err && err === 'route') {117 return done();118 }119120 // signal to exit router121 if (err && err === 'router') {122 return done(err)123 }124125 var layer = stack[idx++];126 if (!layer) {127 return done(err);128 }
88 unmodified lines
modified:test/app.router.js+31 added
930 unmodified lines
931 .expect(200, 'success', done)932 })933 })934935 describe('when next("router") is called', function () {936 it('should jump out of router', function (done) {937 var app = express()938 var router = express.Router()939940 function fn (req, res, next) {941 res.set('X-Hit', '1')942 next('router')943 }944945 router.get('/foo', fn, function (req, res, next) {946 res.end('failure')947 })948949 router.get('/foo', function (req, res, next) {950 res.end('failure')951 })952953 app.use(router)954955 app.get('/foo', function (req, res) {956 res.end('success')957 })958959 request(app)960 .get('/foo')961 .expect('X-Hit', '1')962 .expect(200, 'success', done)963 })964 })965966 describe('when next(err) is called', function(){967 it('should break out of app.router', function(done){968 var app = express()969 , calls = [];
120 unmodified lines
modified:History.md+1 added
1unreleased2==========34 * Add debug message when loading view engine5 * Add `next("router")` to exit from router6 * Fix case where `router.use` skipped requests routes did not7 * Remove usage of `res._headers` private field8 - Improves compatibility with Node.js 8 nightly9 * Skip routing when `req.url` is not set
3223 unmodified lines