Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ Router.prototype.handle = function handle(req, res, callback) {

// store route for dispatch on change
if (route) {
req.route = route
req.route = req.route || { __proto__: route }
req.route.baseUrl = req.baseUrl;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, must remove the habitual ;

}

// Capture one-time layer values
Expand Down
3 changes: 2 additions & 1 deletion lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ Route.prototype.dispatch = function dispatch(req, res, done) {
method = 'get'
}

req.route = this
req.route = req.route || { __proto__: this }
req.route.baseUrl = req.baseUrl;

next()

Expand Down
17 changes: 17 additions & 0 deletions test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,23 @@ describe('Router', function () {
.expect('x-is-route', 'true')
.expect(200, done)
})

it('should have the correct baseUrl', function (done) {
var router = new Router()
var inner = new Router()
var server = createServer(router)

inner[method]('/bar', function handle(req, res) {
res.setHeader('x-route-base', String(req.route.baseUrl === '/foo'))
res.end()
})
router.use('/foo', inner);

request(server)
[method]('/foo/bar')
.expect('x-route-base', 'true')
.expect(200, done)
})
})
})
})
Expand Down