Created
March 14, 2011 21:08
-
-
Save weaver/869889 to your computer and use it in GitHub Desktop.
When nested middleware is used, the `res.app` and `req.app` properties aren't restored when outerNext is called.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In Express 1.0.8, the `res.app` and `req.app` properties aren't restored when | |
// outerNext() is called by nested server middleware. | |
// | |
// Run this script, then try to visit something handled by the `notFound()` middleware | |
// (e.g. `http://localhost:3000/mumble`. An assertion error is raised because `res.app` | |
// is equal to the `middleware()` instead of `app`. | |
var Assert = require('assert'), | |
Express = require('express'), | |
app = Express.createServer(); | |
app.configure(function() { | |
app | |
.use(middleware()) | |
.use(app.router) | |
.use(notFound()); | |
}); | |
function middleware() { | |
var mid = Express.createServer(); | |
mid.get('/mid/example', function(req, res) { | |
res.send('middleware here'); | |
}); | |
return mid; | |
} | |
function notFound() { | |
return function(req, res, next) { | |
Assert.ok(res.app === app, 'Expected main app.'); | |
res.send('not found', 404); | |
}; | |
} | |
app.get('/', function(req, res) { | |
res.send('hello'); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment