koa-router
Advanced tools
Comparing version 7.0.1 to 7.1.0
# History | ||
## 7.1.0 | ||
- Backports: merge 5.4 work into the 7.x upstream. See 5.4.0 updates for more details. | ||
## 7.0.1 | ||
@@ -16,2 +20,6 @@ | ||
## 5.4.0 | ||
- Expose matched route at `ctx._matchedRoute`. | ||
## 5.3.0 | ||
@@ -18,0 +26,0 @@ |
@@ -95,2 +95,3 @@ var debug = require('debug')('koa-router'); | ||
Layer.prototype.captures = function (path) { | ||
if (this.opts.ignoreCaptures) return []; | ||
return path.match(this.regexp).slice(1); | ||
@@ -169,24 +170,19 @@ }; | ||
params.forEach(function (p, i) { | ||
var prev = params[i - 1]; | ||
var names = params.map(function (p) { | ||
return p.name; | ||
}); | ||
if (param === p.name) { | ||
// insert param middleware in order params appear in path | ||
if (prev) { | ||
if (!stack.some(function (m, i) { | ||
if (m.param === prev.name) { | ||
return stack.splice(i, 0, middleware); | ||
} | ||
})) { | ||
stack.some(function (m, i) { | ||
if (!m.param) { | ||
return stack.splice(i, 0, middleware); | ||
} | ||
}); | ||
} | ||
} else { | ||
stack.unshift(middleware); | ||
var x = names.indexOf(param); | ||
if (x > -1) { | ||
// iterate through the stack, to figure out where to place the handler fn | ||
stack.some(function (fn, i) { | ||
// param handlers are always first, so when we find an fn w/o a param property, stop here | ||
// if the param handler at this part of the stack comes after the one we are adding, stop here | ||
if (!fn.param || names.indexOf(fn.param) > x) { | ||
// inject this param handler right before the current item | ||
stack.splice(i, 0, middleware); | ||
return true; // then break the loop | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -193,0 +189,0 @@ return this; |
@@ -87,3 +87,4 @@ /** | ||
* | ||
* Route paths will be translated to regular expressions used to match requests. | ||
* Route paths will be translated to regular expressions using | ||
* [path-to-regexp](https://github.com/pillarjs/path-to-regexp). | ||
* | ||
@@ -244,3 +245,4 @@ * Query strings will not be considered when matching requests. | ||
if (typeof middleware[0] === 'string') { | ||
var hasPath = typeof middleware[0] === 'string'; | ||
if (hasPath) { | ||
path = middleware.shift(); | ||
@@ -263,3 +265,3 @@ } | ||
} else { | ||
router.register(path, [], m, { end: false }); | ||
router.register(path, [], m, { end: false, ignoreCaptures: !hasPath }); | ||
} | ||
@@ -320,2 +322,5 @@ }); | ||
var mostSpecificPath = matched.pathAndMethod[matched.pathAndMethod.length - 1].path; | ||
ctx._matchedRoute = mostSpecificPath; | ||
layerChain = matched.pathAndMethod.reduce(function(memo, layer) { | ||
@@ -487,3 +492,3 @@ memo.push(function(ctx, next) { | ||
* | ||
* @param {String} path Path string or regular expression. | ||
* @param {String} path Path string. | ||
* @param {Array.<String>} methods Array of HTTP verbs. | ||
@@ -517,2 +522,3 @@ * @param {Function} middleware Multiple middleware also accepted. | ||
prefix: opts.prefix || this.opts.prefix || "", | ||
ignoreCaptures: opts.ignoreCaptures | ||
}); | ||
@@ -554,4 +560,3 @@ | ||
/** | ||
* Generate URL for route. Takes either map of named `params` or series of | ||
* arguments (for regular expression routes). | ||
* Generate URL for route. Takes a route name and map of named `params`. | ||
* | ||
@@ -558,0 +563,0 @@ * ```javascript |
@@ -13,3 +13,3 @@ { | ||
"author": "Alex Mingoia <talk@alexmingoia.com>", | ||
"version": "7.0.1", | ||
"version": "7.1.0", | ||
"keywords": [ | ||
@@ -16,0 +16,0 @@ "koa", |
@@ -15,3 +15,3 @@ # koa-router | ||
* Nestable routers. | ||
* ES7 async/await support. | ||
* ES7 async/await support (koa-router 7.x). | ||
@@ -106,3 +106,4 @@ ## Migrating to 7 / Koa 2 | ||
Route paths will be translated to regular expressions used to match requests. | ||
Route paths will be translated to regular expressions using | ||
[path-to-regexp](https://github.com/pillarjs/path-to-regexp). | ||
@@ -135,3 +136,3 @@ Query strings will not be considered when matching requests. | ||
ctx.user = user; | ||
next(); | ||
return next(); | ||
}); | ||
@@ -259,3 +260,3 @@ }, | ||
| [options.throw] | <code>Boolean</code> | throw error instead of setting status and header | | ||
| [options.notImplemented] | <code>Function</code> | throw throw the returned value in place of the default NotImplemented error | | ||
| [options.notImplemented] | <code>Function</code> | throw the returned value in place of the default NotImplemented error | | ||
| [options.methodNotAllowed] | <code>Function</code> | throw the returned value in place of the default MethodNotAllowed error | | ||
@@ -324,4 +325,3 @@ | ||
#### router.url(name, params) ⇒ <code>String</code> | <code>Error</code> | ||
Generate URL for route. Takes either map of named `params` or series of | ||
arguments (for regular expression routes). | ||
Generate URL for route. Takes the route name and a map of named `params`. | ||
@@ -328,0 +328,0 @@ ```javascript |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42120