Skip to content

Commit

Permalink
feat(deps)!: router@^2.0.0 (#5885)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd authored Sep 9, 2024
1 parent 4d713d2 commit 0264908
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions examples/downloads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/resource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/route-separation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/app.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
54 changes: 27 additions & 27 deletions test/app.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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]] }));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
})

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
})

Expand Down Expand Up @@ -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'));
});

Expand All @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand Down
4 changes: 2 additions & 2 deletions test/req.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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)
})
Expand Down

0 comments on commit 0264908

Please sign in to comment.