Socket
Socket
Sign inDemoInstall

koa-router

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-router - npm Package Compare versions

Comparing version 2.4.3 to 2.4.4

5

lib/route.js

@@ -67,3 +67,2 @@ /**

var captures = [];
params = params || [];

@@ -86,3 +85,5 @@ // save route capture groups

else {
params = captures;
for (var i=0, len=captures.length; i<len; i++) {
params[i] = captures[i];
}
}

@@ -89,0 +90,0 @@

26

lib/router.js

@@ -57,9 +57,7 @@ /**

return function *dispatch(next) {
var routes = [];
var matches = [];
this.params = [];
// Find matching route
debug('%s %s', this.method, this.path);
if (!(routes = router.match(this.method, this.path, this.params))) {
if (!(matches = router.match(this.method, this.path))) {
return yield next;

@@ -69,5 +67,7 @@ }

// Dispatch route middlewares
for (var i=0; i<routes.length; i++) {
debug('dispatch "%s" %s', routes[i].path, routes[i].regexp);
yield routes[i].middleware.call(this, next);
for (var i=0, len=matches.length; i<len; i++) {
var route = matches[i].route;
this.params = matches[i].params;
debug('dispatch "%s" %s', route.path, route.regexp);
yield route.middleware.call(this, next);
}

@@ -193,8 +193,7 @@ };

* @param {String} path
* @param {Array} params used to store matched params
* @return {Route|false} Returns matched route or false.
* @return {Array|false} Returns matched routes or false.
* @api private
*/
router.match = function(method, path, params) {
router.match = function(method, path) {
var routes = this.routes[method.toLowerCase()];

@@ -206,5 +205,10 @@ var matchingRoutes = [];

var params = [];
if (routes[i].match(method, path, params)) {
debug('match "%s" %s', routes[i].path, routes[i].regexp);
matchingRoutes.push(routes[i]);
matchingRoutes.push({
route: routes[i],
params: params
});
}

@@ -211,0 +215,0 @@ }

@@ -9,3 +9,3 @@ {

"author": "Alex Mingoia <talk@alexmingoia.com>",
"version": "2.4.3",
"version": "2.4.4",
"keywords": [

@@ -12,0 +12,0 @@ "koa",

@@ -49,2 +49,25 @@ /**

it('populates ctx.params with regexp captures', function(done) {
var app = koa();
app.use(router(app));
app.get(/^\/api\/([^\/]+)\/?/i, function *(next) {
this.should.have.property('params');
this.params.should.be.a('object');
this.params.should.have.property(0, '1');
yield next;
}, function *(next) {
this.should.have.property('params');
this.params.should.be.a('object');
this.params.should.have.property(0, '1');
this.status = 204;
});
request(http.createServer(app.callback()))
.get('/api/1')
.expect(204)
.end(function(err) {
if (err) return done(err);
done();
});
});
it('supports regular expression route paths', function(done) {

@@ -51,0 +74,0 @@ var app = koa();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc