From 91edef7f3012d9017ee7933fad5a7e3deae4d6ae Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Mon, 2 Sep 2024 10:31:46 -0500 Subject: [PATCH] feat(deps)!: router@^2.0.0 --- examples/downloads/index.js | 4 +-- examples/resource/index.js | 2 +- examples/route-separation/index.js | 2 +- package.json | 2 +- test/app.all.js | 2 +- test/app.router.js | 54 +++++++++++++++--------------- test/req.route.js | 4 +-- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/examples/downloads/index.js b/examples/downloads/index.js index 5e48ac3970..c47dddd738 100644 --- a/examples/downloads/index.js +++ b/examples/downloads/index.js @@ -23,8 +23,8 @@ app.get('/', function(req, res){ // /files/* is accessed via req.params[0] // but here we name it :file -app.get('/files/:file+', function (req, res, next) { - res.download(req.params.file, { root: FILES_DIR }, function (err) { +app.get('/files/*file', function (req, res, next) { + res.download(req.params.file.join('/'), { root: FILES_DIR }, function (err) { if (!err) return; // file sent if (err.status !== 404) return next(err); // non-404 error // file for download not found diff --git a/examples/resource/index.js b/examples/resource/index.js index ff1f6fe11f..627ab24c5a 100644 --- a/examples/resource/index.js +++ b/examples/resource/index.js @@ -12,7 +12,7 @@ var app = module.exports = express(); app.resource = function(path, obj) { this.get(path, obj.index); - this.get(path + '/:a..:b.:format?', function(req, res){ + this.get(path + '/:a..:b{.:format}', function(req, res){ var a = parseInt(req.params.a, 10); var b = parseInt(req.params.b, 10); var format = req.params.format; diff --git a/examples/route-separation/index.js b/examples/route-separation/index.js index 5d48381111..a471a4b091 100644 --- a/examples/route-separation/index.js +++ b/examples/route-separation/index.js @@ -38,7 +38,7 @@ app.get('/', site.index); // User app.get('/users', user.list); -app.all('/user/:id/:op?', user.load); +app.all('/user/:id{/:op}', user.load); app.get('/user/:id', user.view); app.get('/user/:id/view', user.view); app.get('/user/:id/edit', user.edit); diff --git a/package.json b/package.json index c89c38f49d..8165354dc6 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "proxy-addr": "~2.0.7", "qs": "6.13.0", "range-parser": "~1.2.1", - "router": "2.0.0-beta.2", + "router": "^2.0.0", "safe-buffer": "5.2.1", "send": "^1.0.0", "serve-static": "^2.0.0", diff --git a/test/app.all.js b/test/app.all.js index 185a8332fe..e4afca7d73 100644 --- a/test/app.all.js +++ b/test/app.all.js @@ -26,7 +26,7 @@ describe('app.all()', function(){ var app = express() , n = 0; - app.all('/*', function(req, res, next){ + app.all('/*splat', function(req, res, next){ if (n++) return done(new Error('DELETE called several times')); next(); }); diff --git a/test/app.router.js b/test/app.router.js index d6f3edf1ab..7961aa348d 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -316,12 +316,12 @@ describe('app.router', function(){ var app = express(); var router = new express.Router({ mergeParams: true }); - router.get('/(.*).(.*)', function (req, res) { + router.get(/^\/(.*)\.(.*)/, function (req, res) { var keys = Object.keys(req.params).sort(); res.send(keys.map(function(k){ return [k, req.params[k]] })); }); - app.use('/user/id:(\\d+)', router); + app.use(/^\/user\/id:(\d+)/, router); request(app) .get('/user/id:10/profile.json') @@ -332,12 +332,12 @@ describe('app.router', function(){ var app = express(); var router = new express.Router({ mergeParams: true }); - router.get('/(.*)', function (req, res) { + router.get(/\/(.*)/, function (req, res) { var keys = Object.keys(req.params).sort(); res.send(keys.map(function(k){ return [k, req.params[k]] })); }); - app.use('/user/id:(\\d+)/name:(\\w+)', router); + app.use(/^\/user\/id:(\d+)\/name:(\w+)/, router); request(app) .get('/user/id:10/name:tj/profile') @@ -348,12 +348,12 @@ describe('app.router', function(){ var app = express(); var router = new express.Router({ mergeParams: true }); - router.get('/name:(\\w+)', function(req, res){ + router.get(/\/name:(\w+)/, function(req, res){ var keys = Object.keys(req.params).sort(); res.send(keys.map(function(k){ return [k, req.params[k]] })); }); - app.use('/user/id:(\\d+)', router); + app.use(/\/user\/id:(\d+)/, router); request(app) .get('/user/id:10/name:tj') @@ -383,11 +383,11 @@ describe('app.router', function(){ var app = express(); var router = new express.Router({ mergeParams: true }); - router.get('/user:(\\w+)/*', function (req, res, next) { + router.get(/\/user:(\w+)\//, function (req, res, next) { next(); }); - app.use('/user/id:(\\d+)', function (req, res, next) { + app.use(/\/user\/id:(\d+)/, function (req, res, next) { router(req, res, function (err) { var keys = Object.keys(req.params).sort(); res.send(keys.map(function(k){ return [k, req.params[k]] })); @@ -610,8 +610,8 @@ describe('app.router', function(){ var app = express(); var cb = after(2, done); - app.get('/user(s?)/:user/:op', function(req, res){ - res.end(req.params.op + 'ing ' + req.params.user + (req.params[0] ? ' (old)' : '')); + app.get('/user{s}/:user/:op', function(req, res){ + res.end(req.params.op + 'ing ' + req.params.user + (req.url.startsWith('/users') ? ' (old)' : '')); }); request(app) @@ -657,7 +657,7 @@ describe('app.router', function(){ it('should denote an optional capture group', function(done){ var app = express(); - app.get('/user/:user/:op?', function(req, res){ + app.get('/user/:user{/:op}', function(req, res){ var op = req.params.op || 'view'; res.end(op + 'ing ' + req.params.user); }); @@ -670,7 +670,7 @@ describe('app.router', function(){ it('should populate the capture group', function(done){ var app = express(); - app.get('/user/:user/:op?', function(req, res){ + app.get('/user/:user{/:op}', function(req, res){ var op = req.params.op || 'view'; res.end(op + 'ing ' + req.params.user); }); @@ -685,8 +685,8 @@ describe('app.router', function(){ it('should match one segment', function (done) { var app = express() - app.get('/user/:user*', function (req, res) { - res.end(req.params.user) + app.get('/user/*user', function (req, res) { + res.end(req.params.user[0]) }) request(app) @@ -697,8 +697,8 @@ describe('app.router', function(){ it('should match many segments', function (done) { var app = express() - app.get('/user/:user*', function (req, res) { - res.end(req.params.user) + app.get('/user/*user', function (req, res) { + res.end(req.params.user.join('/')) }) request(app) @@ -709,7 +709,7 @@ describe('app.router', function(){ it('should match zero segments', function (done) { var app = express() - app.get('/user/:user*', function (req, res) { + app.get('/user{/*user}', function (req, res) { res.end(req.params.user) }) @@ -723,8 +723,8 @@ describe('app.router', function(){ it('should match one segment', function (done) { var app = express() - app.get('/user/:user+', function (req, res) { - res.end(req.params.user) + app.get('/user/*user', function (req, res) { + res.end(req.params.user[0]) }) request(app) @@ -735,8 +735,8 @@ describe('app.router', function(){ it('should match many segments', function (done) { var app = express() - app.get('/user/:user+', function (req, res) { - res.end(req.params.user) + app.get('/user/*user', function (req, res) { + res.end(req.params.user.join('/')) }) request(app) @@ -747,7 +747,7 @@ describe('app.router', function(){ it('should not match zero segments', function (done) { var app = express() - app.get('/user/:user+', function (req, res) { + app.get('/user/*user', function (req, res) { res.end(req.params.user) }) @@ -781,7 +781,7 @@ describe('app.router', function(){ var app = express(); var cb = after(2, done) - app.get('/:name.:format?', function(req, res){ + app.get('/:name{.:format}', function(req, res){ res.end(req.params.name + ' as ' + (req.params.format || 'html')); }); @@ -800,7 +800,7 @@ describe('app.router', function(){ var app = express() , calls = []; - app.get('/foo/:bar?', function(req, res, next){ + app.get('/foo{/:bar}', function(req, res, next){ calls.push('/foo/:bar?'); next(); }); @@ -885,7 +885,7 @@ describe('app.router', function(){ var app = express() , calls = []; - app.get('/foo/:bar?', function(req, res, next){ + app.get('/foo{/:bar}', function(req, res, next){ calls.push('/foo/:bar?'); next(); }); @@ -1096,7 +1096,7 @@ describe('app.router', function(){ var app = express(); var path = []; - app.get('/:path+', function (req, res, next) { + app.get('/*path', function (req, res, next) { path.push(0); next(); }); @@ -1116,7 +1116,7 @@ describe('app.router', function(){ next(); }); - app.get('/(.*)', function (req, res, next) { + app.get('/*splat', function (req, res, next) { path.push(4); next(); }); diff --git a/test/req.route.js b/test/req.route.js index 6c17fbb1c8..9bd7ed923b 100644 --- a/test/req.route.js +++ b/test/req.route.js @@ -8,7 +8,7 @@ describe('req', function(){ it('should be the executed Route', function(done){ var app = express(); - app.get('/user/:id/:op?', function(req, res, next){ + app.get('/user/:id{/:op}', function(req, res, next){ res.header('path-1', req.route.path) next(); }); @@ -20,7 +20,7 @@ describe('req', function(){ request(app) .get('/user/12/edit') - .expect('path-1', '/user/:id/:op?') + .expect('path-1', '/user/:id{/:op}') .expect('path-2', '/user/:id/edit') .expect(200, done) })