@koa/router 9.2.0 → 10.0.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 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
@@ -362,7 +362,7 @@ Router.prototype.routes = Router.prototype.middleware = function () {
362
362
  layerChain = matchedLayers.reduce(function(memo, layer) {
363
363
  memo.push(function(ctx, next) {
364
364
  ctx.captures = layer.captures(path, ctx.captures);
365
- ctx.params = layer.params(path, ctx.captures, ctx.params);
365
+ ctx.params = ctx.request.params = layer.params(path, ctx.captures, ctx.params);
366
366
  ctx.routerPath = layer.path;
367
367
  ctx.routerName = layer.name;
368
368
  ctx._matchedRoute = layer.path;
@@ -532,7 +532,7 @@ Router.prototype.redirect = function (source, destination, code) {
532
532
  if (source[0] !== '/') source = this.url(source);
533
533
 
534
534
  // lookup destination route by name
535
- if (destination[0] !== '/') destination = this.url(destination);
535
+ if (destination[0] !== '/' && !destination.includes('://')) destination = this.url(destination);
536
536
 
537
537
  return this.all(source, ctx => {
538
538
  ctx.redirect(destination);
@@ -588,6 +588,8 @@ Router.prototype.register = function (path, methods, middleware, opts) {
588
588
 
589
589
  stack.push(route);
590
590
 
591
+ debug('defined route %s %s', route.methods, route.path);
592
+
591
593
  return route;
592
594
  };
593
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.2.0",
4
+ "version": "10.0.0",
5
5
  "author": "Alex Mingoia <talk@alexmingoia.com>",
6
6
  "bugs": {
7
7
  "url": "https://github.com/koajs/router/issues",