Merge branch 'integration'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parents 80f4d08, 90d7e19 · Browse files · 2 files·+53 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+53 added−17 removed
- tests:+26 added−1 removed
- other:+27 added−16 removed
Provenance
- Commit
f3c068a- Tree
046c319- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent 1
80f4d08- Parent 2
90d7e19
2 files changed+53 added−17 removed
modified:lib/http.js+27 added-16 removed
49 unmodified lines50 this.viewHelpers = {};51 this.dynamicViewHelpers = {};52 this.errorHandlers = [];53 54- // default "home" to / 54+ // default "home" to /55 this.set('home', '/');56 57 // set "env" to NODE_ENV, defaulting to "development"58 this.set('env', process.env.NODE_ENV || 'development');73 unmodified lines132 * @api public133 */134 135 Server.prototype.use = function(route, middleware){136- var app, home;136+ var app, home, handle;137 138 if ('string' != typeof route) {139 middleware = route, route = '/';140 }141 142+ // express app143+ if (middleware.handle && middleware.set) app = middleware;144+145+ // restore .app property on req and res146+ if (app) {147+ app.route = route;148+ middleware = function(req, res, next) {149+ var orig = req.app;150+ app.handle(req, res, function(err){151+ req.app = res.app = orig;152+ next(err);153+ });154+ };155+ }156+157 connect.HTTPServer.prototype.use.call(this, route, middleware);158 144- // mounted an app145- if (middleware.handle) {146- app = middleware;147- // express app148- if (app.set) {149- home = app.set('home');150- if ('/' == home) home = '';151- app.set('home', app.route + home);152- app.parent = this;159+ // mounted an app, invoke the hook160+ // and adjust some settings161+ if (app) {162+ home = app.set('home');163+ if ('/' == home) home = '';164+ app.set('home', app.route + home);165+ app.parent = this;153- }154- // mounted hook166 if (app.__mounted) app.__mounted.call(app, this);167 }168 169 return this;45 unmodified lines215 * @return {Server} for chaining216 * @api public217 */218 208-Server.prototype.helpers = 219+Server.prototype.helpers =220 Server.prototype.locals = function(obj){221 utils.merge(this.viewHelpers, obj);222 return this;223 };16 unmodified lines240 * Map the given param placeholder `name`(s) to the given callback `fn`.241 *242 * Param mapping is used to provide pre-conditions to routes243 * which us normalized placeholders. For example ":user_id" may233- * attempt to load the user from the database, where as ":num" may 244+ * attempt to load the user from the database, where as ":num" may245 * pass the value through `parseInt(num, 10)`.246 *247 * When the callback function accepts only a single argument, the248 * value of placeholder is passed:249 *250 * app.param('page', function(n){ return parseInt(n, 10); });251 *252 * After which "/users/:page" would automatically provide us with242- * an integer for `req.params.page`. If desired we could use the callback 253+ * an integer for `req.params.page`. If desired we could use the callback254 * signature shown below, and immediately `next(new Error('invalid page'))`255 * when `parseInt` fails.256 *257 * Alternatively the callback may accept the request, response, next, and207 unmodified linesmodified:test/express.test.js+26 added-1 removed
404 unmodified lines405 assert.response(app,406 { url: '/regular' },407 { body: 'hey' });408 },409+410+ 'test .app property after returning control to parent': function() {411+ var app = express.createServer()412+ , blog = express.createServer();413+414+ // Mounted servers did not restore `req.app` and `res.app` when415+ // passing control back to parent via `out()` in `#handle()`.416+417+ blog.get('/', function(req, res, next){418+ req.app.should.equal(blog);419+ res.app.should.equal(blog);420+ next();421+ });422+423+ app.use(blog);424+425+ app.use(function(req, res, next) {426+ res.send((res.app === app) ? 'restored' : 'not-restored');427+ });428+429+ assert.response(app,430+ { url: '/' },431+ { body: 'restored' }432+ );433+ },434 435 'test route middleware': function(){436 var app = express.createServer();437 120 unmodified lines558 assert.response(app,559 { url: '/user/12', method: 'OPTIONS' },560 { headers: { Allow: 'GET,PUT' }});561 }537-};562+};