Skip to content

Commit

Permalink
Clean up patch to Server#use(), add test case for restoring res#app p…
Browse files Browse the repository at this point in the history
…roperty.
  • Loading branch information
weaver authored and tj committed Mar 15, 2011
1 parent f12baf3 commit 9865a4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/http.js
Expand Up @@ -156,9 +156,9 @@ Server.prototype.use = function(route, middleware){
middleware.route = route;
handle = function(req, res, next) {
var origApp = res.app;
middleware.handle(req, res, next && function() {
middleware.handle(req, res, function(err) {
req.app = res.app = origApp;
return next.apply(this, arguments);
return next(err);
});
};
}
Expand Down
20 changes: 19 additions & 1 deletion test/express.test.js
Expand Up @@ -406,6 +406,24 @@ module.exports = {
{ url: '/regular' },
{ body: 'hey' });
},

'test .app property after returning control to parent': function() {
var app = express.createServer();

// Mounted servers did not restore `req.app` and `res.app` when
// passing control back to parent via `out()` in `#handle()`.

app.use(express.createServer());

app.use(function(req, res, next) {
res.send((res.app === app) ? 'restored' : 'not-restored');
});

assert.response(app,
{ url: '/' },
{ body: 'restored' }
);
},

'test route middleware': function(){
var app = express.createServer();
Expand Down Expand Up @@ -534,4 +552,4 @@ module.exports = {
{ url: '/user/12', method: 'OPTIONS' },
{ headers: { Allow: 'GET,PUT' }});
}
};
};

0 comments on commit 9865a4c

Please sign in to comment.