Merge branch 'fix-home'
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 baae446, bab095e · Browse files · 2 files·+38 added−8 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+38 added−8 removed
- tests:+8 added−2 removed
- other:+30 added−6 removed
Provenance
- Commit
16a24cf- Tree
2469902- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent 1
baae446- Parent 2
bab095e
2 files changed+38 added−8 removed
modified:lib/express/server.js+30 added-6 removed
31 unmodified lines32 this.viewHelpers = {};33 this.dynamicViewHelpers = {};34 connect.Server.call(this, middleware || []);35 36+ // Default "home" to / 37+ this.set('home', '/');38+39 // Set "env" to {EXPRESS,CONNECT}_ENV40 this.set('env', process.env.EXPRESS_ENV || process.connectEnv.name);41 42 // Expose objects to each other36 unmodified lines79 * @api public80 */81 82 Server.prototype.listen = function(port, host){80- // Default "home" to the mounted route or '/'81- if (!this.set('home')) {82- this.set('home', this.route || '/');83- }84-83 // Setup view reloading84 if (this.set('reload views')) {85 view.watcher.call(this, this.set('reload views'));86 }89-87 connect.Server.prototype.listen.call(this, port, host);88 };89 90 /**91+ * Proxy `connect.Server#use()` to apply settings to92+ * mounted applications.93+ *94+ * @param {String|Function|Server} route95+ * @param {Function|Server} middleware96+ * @return {Server} for chaining97+ * @api public98+ */99+100+Server.prototype.use = function(route, middleware){101+ if (typeof route !== 'string') {102+ middleware = route, route = '/';103+ }104+105+ connect.Server.prototype.use.call(this, route, middleware);106+107+ if (middleware instanceof Server) {108+ var app = middleware,109+ home = app.set('home');110+ if (home === '/') home = '';111+ app.set('home', (app.route || '') + home);112+ }113+114+ return this;115+};116+117+/**118 * Register the given view helpers `obj`. This method119 * can be called several times to apply additional helpers.120 *121 * @param {Object} obj125 unmodified linesmodified:test/express.test.js+8 added-2 removed
265 unmodified lines266 },267 268 'test mounting': function(assert){269 var app = express.createServer(),270- blog = express.createServer();270+ blog = express.createServer(),271+ map = express.createServer();272+273+ map.set('home', '/map');274 275 app.use('/blog', blog);276+ app.use('/contact', map);277 assert.equal('/blog', blog.route);278+ assert.equal('/contact', map.route);279 280 app.get('/', function(req, res){276- assert.equal('/', app.set('home'), "home did not default /");281+ assert.equal('/', app.set('home'), "home did not default to /");282 assert.equal('/blog', blog.set('home'), "home did not default to Server#route when mounted");283+ assert.equal('/contact/map', map.set('home'), 'home did not prepend route on Server#use()');284 res.send('main app');285 });286 287 blog.get('/', function(req, res){21 unmodified lines