Socket
Socket
Sign inDemoInstall

@koa/router

Package Overview
Dependencies
Maintainers
8
Versions
26
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 8.0.6 to 8.0.7

13

lib/layer.js

@@ -28,11 +28,12 @@ var debug = require('debug')('koa-router');

methods.forEach(function(method) {
var l = this.methods.push(method.toUpperCase());
for(var i = 0; i < methods.length; i++) {
var l = this.methods.push(methods[i].toUpperCase());
if (this.methods[l-1] === 'GET') {
this.methods.unshift('HEAD');
this.methods.unshift('HEAD');
}
}, this);
}
// ensure middleware is a function
this.stack.forEach(function(fn) {
for (var i = 0; i < this.stack.length; i++) {
var fn = this.stack[i];
var type = (typeof fn);

@@ -45,3 +46,3 @@ if (type !== 'function') {

}
}, this);
}

@@ -48,0 +49,0 @@ this.path = path;

@@ -190,21 +190,24 @@ /**

methods.forEach(function (method) {
Router.prototype[method] = function (name, path, middleware) {
var middleware;
for (var i = 0; i < methods.length; i++) {
function setMethodVerb(method) {
Router.prototype[method] = function(name, path, middleware) {
var middleware;
if (typeof path === 'string' || path instanceof RegExp) {
middleware = Array.prototype.slice.call(arguments, 2);
} else {
middleware = Array.prototype.slice.call(arguments, 1);
path = name;
name = null;
}
if (typeof path === "string" || path instanceof RegExp) {
middleware = Array.prototype.slice.call(arguments, 2);
} else {
middleware = Array.prototype.slice.call(arguments, 1);
path = name;
name = null;
}
this.register(path, [method], middleware, {
name: name
});
this.register(path, [method], middleware, {
name: name
});
return this;
};
});
return this;
};
}
setMethodVerb(methods[i]);
}

@@ -251,6 +254,7 @@ // Alias for `router.delete()` because delete is a reserved word

if (Array.isArray(middleware[0]) && typeof middleware[0][0] === 'string') {
middleware[0].forEach(function (p) {
var arrPaths = middleware[0];
for (var i = 0; i < arrPaths.length; i++) {
var p = arrPaths[i];
router.use.apply(router, [p].concat(middleware.slice(1)));
});
}
return this;

@@ -264,10 +268,15 @@ }

middleware.forEach(function (m) {
for (var i = 0; i < middleware.length; i++) {
var m = middleware[i];
if (m.router) {
const cloneRouter = Object.assign(Object.create(Router.prototype), m.router, {
var cloneRouter = Object.assign(Object.create(Router.prototype), m.router, {
stack: m.router.stack.slice(0)
});
cloneRouter.stack.forEach(function (nestedLayer, index) {
const cloneLayer = Object.assign(Object.create(Layer.prototype), nestedLayer);
for (var i = 0; i < cloneRouter.stack.length; i++) {
var nestedLayer = cloneRouter.stack[i];
var cloneLayer = Object.assign(
Object.create(Layer.prototype),
nestedLayer
);

@@ -277,9 +286,14 @@ if (path) cloneLayer.setPrefix(path);

router.stack.push(cloneLayer);
this[index] = cloneLayer;
}, cloneRouter.stack);
cloneRouter.stack[i] = cloneLayer;
}
if (router.params) {
Object.keys(router.params).forEach(function (key) {
cloneRouter.param(key, router.params[key]);
});
function setRouterParams(paramArr) {
var routerParams = paramArr;
for (var i = 0; i < routerParams.length; i++) {
var key = routerParams[i];
cloneRouter.param(key, router.params[key]);
}
}
setRouterParams(Object.keys(router.params));
}

@@ -289,3 +303,3 @@ } else {

}
});
}

@@ -313,6 +327,7 @@ return this;

this.stack.forEach(function (route) {
for (var i = 0; i < this.stack.length; i++) {
var route = this.stack[i];
route.setPrefix(prefix);
});
}
return this;

@@ -424,7 +439,9 @@ };

if (!ctx.status || ctx.status === 404) {
ctx.matched.forEach(function (route) {
route.methods.forEach(function (method) {
allowed[method] = method;
});
});
for (var i = 0; i < ctx.matched.length; i++) {
var route = ctx.matched[i];
for (var j = 0; j < route.methods.length; j++) {
var method = route.methods[j];
allowed[method] = method
}
}

@@ -559,5 +576,6 @@ var allowedArr = Object.keys(allowed);

if (Array.isArray(path)) {
path.forEach(function (p) {
router.register.call(router, p, methods, middleware, opts);
});
for (var i = 0; i < path.length; i++) {
var curPath = path[i];
router.register.call(router, curPath, methods, middleware, opts);
}

@@ -582,5 +600,6 @@ return this;

// add parameter middleware
Object.keys(this.params).forEach(function (param) {
for (var i = 0; i < Object.keys(this.params).length; i++) {
var param = Object.keys(this.params)[i];
route.param(param, this.params[param]);
}, this);
}

@@ -724,7 +743,9 @@ stack.push(route);

Router.prototype.param = function (param, middleware) {
Router.prototype.param = function(param, middleware) {
this.params[param] = middleware;
this.stack.forEach(function (route) {
for (var i = 0; i < this.stack.length; i++) {
var route = this.stack[i];
route.param(param, middleware);
});
}
return this;

@@ -747,5 +768,5 @@ };

*/
Router.url = function (path, params) {
Router.url = function (path) {
var args = Array.prototype.slice.call(arguments, 1);
return Layer.prototype.url.apply({ path: path }, args);
};
{
"name": "@koa/router",
"description": "Router middleware for koa. Provides RESTful resource routing.",
"version": "8.0.6",
"version": "8.0.7",
"author": "Alex Mingoia <talk@alexmingoia.com>",

@@ -6,0 +6,0 @@ "bugs": {

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