mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
parent
8b6dc6ceec
commit
51f52901eb
|
|
@ -2,6 +2,7 @@ unreleased
|
||||||
==========
|
==========
|
||||||
|
|
||||||
* Add debug message when loading view engine
|
* Add debug message when loading view engine
|
||||||
|
* Fix case where `router.use` skipped requests routes did not
|
||||||
* Remove usage of `res._headers` private field
|
* Remove usage of `res._headers` private field
|
||||||
- Improves compatibility with Node.js 8 nightly
|
- Improves compatibility with Node.js 8 nightly
|
||||||
* Skip routing when `req.url` is not set
|
* Skip routing when `req.url` is not set
|
||||||
|
|
|
||||||
|
|
@ -280,12 +280,13 @@ proto.handle = function handle(req, res, out) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function trim_prefix(layer, layerError, layerPath, path) {
|
function trim_prefix(layer, layerError, layerPath, path) {
|
||||||
var c = path[layerPath.length];
|
if (layerPath.length !== 0) {
|
||||||
if (c && '/' !== c && '.' !== c) return next(layerError);
|
// Validate path breaks on a path separator
|
||||||
|
var c = path[layerPath.length]
|
||||||
|
if (c && c !== '/' && c !== '.') return next(layerError)
|
||||||
|
|
||||||
// Trim off the part of the url that matches the route
|
// Trim off the part of the url that matches the route
|
||||||
// middleware (.use stuff) needs to have the path stripped
|
// middleware (.use stuff) needs to have the path stripped
|
||||||
if (layerPath.length !== 0) {
|
|
||||||
debug('trim prefix (%s) from url %s', layerPath, req.url);
|
debug('trim prefix (%s) from url %s', layerPath, req.url);
|
||||||
removed = layerPath;
|
removed = layerPath;
|
||||||
req.url = protohost + req.url.substr(protohost.length + removed.length);
|
req.url = protohost + req.url.substr(protohost.length + removed.length);
|
||||||
|
|
|
||||||
|
|
@ -347,6 +347,24 @@ describe('Router', function(){
|
||||||
assert.equal(count, methods.length);
|
assert.equal(count, methods.length);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should be called for any URL when "*"', function (done) {
|
||||||
|
var cb = after(4, done)
|
||||||
|
var router = new Router()
|
||||||
|
|
||||||
|
function no () {
|
||||||
|
throw new Error('should not be called')
|
||||||
|
}
|
||||||
|
|
||||||
|
router.all('*', function (req, res) {
|
||||||
|
res.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
router.handle({ url: '/', method: 'GET' }, { end: cb }, no)
|
||||||
|
router.handle({ url: '/foo', method: 'GET' }, { end: cb }, no)
|
||||||
|
router.handle({ url: 'foo', method: 'GET' }, { end: cb }, no)
|
||||||
|
router.handle({ url: '*', method: 'GET' }, { end: cb }, no)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('.use', function() {
|
describe('.use', function() {
|
||||||
|
|
@ -363,6 +381,24 @@ describe('Router', function(){
|
||||||
router.use.bind(router, '/', new Date()).should.throw(/requires middleware function.*Date/)
|
router.use.bind(router, '/', new Date()).should.throw(/requires middleware function.*Date/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should be called for any URL', function (done) {
|
||||||
|
var cb = after(4, done)
|
||||||
|
var router = new Router()
|
||||||
|
|
||||||
|
function no () {
|
||||||
|
throw new Error('should not be called')
|
||||||
|
}
|
||||||
|
|
||||||
|
router.use(function (req, res) {
|
||||||
|
res.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
router.handle({ url: '/', method: 'GET' }, { end: cb }, no)
|
||||||
|
router.handle({ url: '/foo', method: 'GET' }, { end: cb }, no)
|
||||||
|
router.handle({ url: 'foo', method: 'GET' }, { end: cb }, no)
|
||||||
|
router.handle({ url: '*', method: 'GET' }, { end: cb }, no)
|
||||||
|
})
|
||||||
|
|
||||||
it('should accept array of middleware', function(done){
|
it('should accept array of middleware', function(done){
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var router = new Router();
|
var router = new Router();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user