Skip to content
Myr

Fixed mounting of non-express servers

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 · parent 65c8a95 · Browse files · 2 files+19 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+19 added−8 removed

  • tests:+9 added−2 removed
  • other:+10 added−6 removed

2 files+19 added−8 removed

modified:lib/http.js+10 added-6 removed
126 unmodified lines
127 * @api public128 */129130Server.prototype.use = function(route, middleware){131 var app, home;132133 if ('string' != typeof route) {134 middleware = route, route = '/';135 }136137 connect.HTTPServer.prototype.use.call(this, route, middleware);138139 // mounted an app140 if (middleware.handle) {139 // home is /:route/:home140 var app = middleware141 , home = app.set('home');142 if (home === '/') home = '';143 app.set('home', (app.route || '') + home);144 app.parent = this;141 app = middleware;142 // express app143 if (app.set) {144 home = app.set('home');145 if ('/' == home) home = '';146 app.set('home', app.route + home);147 app.parent = this;148 }149 // mounted hook150 if (app.__mounted) app.__mounted.call(app, this);151 }152
296 unmodified lines
modified:test/express.test.js+9 added-2 removed
345 unmodified lines
346 'test mounting': function(){347 var called348 , app = express.createServer()349 , blog = express.createServer()350 , map = express.createServer();350 , map = express.createServer()351 , reg = connect.createServer();352353 map.set('home', '/map');354 355 map.mounted(function(parent){356 called = true;357 assert.equal(this, map, 'mounted() is not in context of the child app');358 assert.equal(app, parent, 'mounted() was not called with parent app');359 });359 360361 reg.use(function(req, res){ res.end('hey'); });362 app.use('/regular', reg);363364 app.use('/blog', blog);365 app.use('/contact', map);366 blog.route.should.equal('/blog');367 map.route.should.equal('/contact');
28 unmodified lines
396 { body: 'blog post 12' });397 assert.response(blog,398 { url: '/' },399 { body: 'blog index' });400 assert.response(app,401 { url: '/regular' },402 { body: 'hey' });403 },404 405 'test route middleware': function(){406 var app = express.createServer();
126 unmodified lines