@koa/router 9.1.0 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/layer.js +1 -4
- package/lib/router.js +8 -2
- package/package.json +1 -1
package/lib/layer.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const debug = require('debug')('koa-router');
|
|
2
1
|
const { pathToRegexp, compile, parse } = require('path-to-regexp');
|
|
3
2
|
const { parse: parseUrl, format: formatUrl } = require('url');
|
|
4
3
|
|
|
@@ -42,8 +41,6 @@ function Layer(path, methods, middleware, opts) {
|
|
|
42
41
|
|
|
43
42
|
this.path = path;
|
|
44
43
|
this.regexp = pathToRegexp(path, this.paramNames, this.opts);
|
|
45
|
-
|
|
46
|
-
debug('defined route %s %s', this.methods, `${this.opts.prefix}${this.path}`);
|
|
47
44
|
};
|
|
48
45
|
|
|
49
46
|
/**
|
|
@@ -133,7 +130,7 @@ Layer.prototype.url = function (params, options) {
|
|
|
133
130
|
}
|
|
134
131
|
} else if (tokens.some(token => token.name)) {
|
|
135
132
|
replace = params;
|
|
136
|
-
} else {
|
|
133
|
+
} else if (!options) {
|
|
137
134
|
options = params;
|
|
138
135
|
}
|
|
139
136
|
|
package/lib/router.js
CHANGED
|
@@ -10,6 +10,7 @@ const compose = require('koa-compose');
|
|
|
10
10
|
const HttpError = require('http-errors');
|
|
11
11
|
const methods = require('methods');
|
|
12
12
|
const Layer = require('./layer');
|
|
13
|
+
const { pathToRegexp } = require('path-to-regexp');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @module koa-router
|
|
@@ -289,7 +290,10 @@ Router.prototype.use = function () {
|
|
|
289
290
|
setRouterParams(Object.keys(router.params));
|
|
290
291
|
}
|
|
291
292
|
} else {
|
|
292
|
-
|
|
293
|
+
const keys = [];
|
|
294
|
+
pathToRegexp(router.opts.prefix || '', keys);
|
|
295
|
+
const routerPrefixHasParam = router.opts.prefix && keys.length;
|
|
296
|
+
router.register(path || '([^\/]*)', [], m, { end: false, ignoreCaptures: !hasPath && !routerPrefixHasParam });
|
|
293
297
|
}
|
|
294
298
|
}
|
|
295
299
|
|
|
@@ -358,7 +362,7 @@ Router.prototype.routes = Router.prototype.middleware = function () {
|
|
|
358
362
|
layerChain = matchedLayers.reduce(function(memo, layer) {
|
|
359
363
|
memo.push(function(ctx, next) {
|
|
360
364
|
ctx.captures = layer.captures(path, ctx.captures);
|
|
361
|
-
ctx.params = layer.params(path, ctx.captures, ctx.params);
|
|
365
|
+
ctx.params = ctx.request.params = layer.params(path, ctx.captures, ctx.params);
|
|
362
366
|
ctx.routerPath = layer.path;
|
|
363
367
|
ctx.routerName = layer.name;
|
|
364
368
|
ctx._matchedRoute = layer.path;
|
|
@@ -584,6 +588,8 @@ Router.prototype.register = function (path, methods, middleware, opts) {
|
|
|
584
588
|
|
|
585
589
|
stack.push(route);
|
|
586
590
|
|
|
591
|
+
debug('defined route %s %s', route.methods, route.path);
|
|
592
|
+
|
|
587
593
|
return route;
|
|
588
594
|
};
|
|
589
595
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koa/router",
|
|
3
3
|
"description": "Router middleware for koa. Provides RESTful resource routing.",
|
|
4
|
-
"version": "9.
|
|
4
|
+
"version": "9.4.0",
|
|
5
5
|
"author": "Alex Mingoia <talk@alexmingoia.com>",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/koajs/router/issues",
|