@eggjs/router 2.0.1 → 2.1.1
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/README.md +50 -18
- package/lib/egg_router.js +5 -5
- package/lib/layer.js +1 -1
- package/lib/router.js +1 -1
- package/lib/utils.js +20 -4
- package/package.json +10 -13
- package/History.md +0 -187
package/README.md
CHANGED
|
@@ -3,36 +3,42 @@
|
|
|
3
3
|
Router core component for [Egg.js](https://github.com/eggjs).
|
|
4
4
|
|
|
5
5
|
> **This repository is a fork of [koa-router](https://github.com/alexmingoia/koa-router).** with some additional features.
|
|
6
|
-
|
|
7
|
-
> And thanks for the greate work of @alexmingoia and the original team.
|
|
6
|
+
> And thanks for the great work of @alexmingoia and the original team.
|
|
8
7
|
|
|
9
8
|
## API Reference
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
- [@eggjs/router](#eggjsrouter)
|
|
11
|
+
- [API Reference](#api-reference)
|
|
12
|
+
- [Router ⏏](#router-)
|
|
13
|
+
- [new Router(\[opts\])](#new-routeropts)
|
|
14
|
+
- [router.get|put|post|patch|delete|del ⇒ Router](#routergetputpostpatchdeletedel--router)
|
|
15
|
+
- [Named routes](#named-routes)
|
|
16
|
+
- [Multiple middleware](#multiple-middleware)
|
|
17
|
+
- [Nested routers](#nested-routers)
|
|
18
|
+
- [Router prefixes](#router-prefixes)
|
|
19
|
+
- [URL parameters](#url-parameters)
|
|
20
|
+
- [router.routes ⇒ function](#routerroutes--function)
|
|
21
|
+
- [router.use(\[path\], middleware) ⇒ Router](#routerusepath-middleware--router)
|
|
22
|
+
- [router.prefix(prefix) ⇒ Router](#routerprefixprefix--router)
|
|
23
|
+
- [router.allowedMethods(\[options\]) ⇒ function](#routerallowedmethodsoptions--function)
|
|
24
|
+
- [router.redirect(source, destination, \[code\]) ⇒ Router](#routerredirectsource-destination-code--router)
|
|
25
|
+
- [router.route(name) ⇒ Layer | false](#routerroutename--layer--false)
|
|
26
|
+
- [router.url(name, params, \[options\]) ⇒ String | Error](#routerurlname-params-options--string--error)
|
|
27
|
+
- [router.param(param, middleware) ⇒ Router](#routerparamparam-middleware--router)
|
|
28
|
+
- [Router.url(path, params \[, options\]) ⇒ String](#routerurlpath-params--options--string)
|
|
29
|
+
- [Tests](#tests)
|
|
30
|
+
- [License](#license)
|
|
26
31
|
|
|
27
32
|
<a name="exp_module_egg-router--Router"></a>
|
|
28
33
|
|
|
29
34
|
### Router ⏏
|
|
35
|
+
|
|
30
36
|
**Kind**: Exported class
|
|
31
37
|
<a name="new_module_egg-router--Router_new"></a>
|
|
32
38
|
|
|
33
39
|
#### new Router([opts])
|
|
34
|
-
Create a new router.
|
|
35
40
|
|
|
41
|
+
Create a new router.
|
|
36
42
|
|
|
37
43
|
| Param | Type | Description |
|
|
38
44
|
| --- | --- | --- |
|
|
@@ -57,9 +63,11 @@ app
|
|
|
57
63
|
.use(router.routes())
|
|
58
64
|
.use(router.allowedMethods());
|
|
59
65
|
```
|
|
66
|
+
|
|
60
67
|
<a name="module_egg-router--Router+get|put|post|patch|delete|del"></a>
|
|
61
68
|
|
|
62
69
|
#### router.get|put|post|patch|delete|del ⇒ <code>Router</code>
|
|
70
|
+
|
|
63
71
|
Create `router.verb()` methods, where *verb* is one of the HTTP verbs such
|
|
64
72
|
as `router.get()` or `router.post()`.
|
|
65
73
|
|
|
@@ -183,12 +191,14 @@ used to convert paths to regular expressions.
|
|
|
183
191
|
<a name="module_egg-router--Router+routes"></a>
|
|
184
192
|
|
|
185
193
|
#### router.routes ⇒ <code>function</code>
|
|
194
|
+
|
|
186
195
|
Returns router middleware which dispatches a route matching the request.
|
|
187
196
|
|
|
188
197
|
**Kind**: instance property of <code>[Router](#exp_module_egg-router--Router)</code>
|
|
189
198
|
<a name="module_egg-router--Router+use"></a>
|
|
190
199
|
|
|
191
200
|
#### router.use([path], middleware) ⇒ <code>Router</code>
|
|
201
|
+
|
|
192
202
|
Use given middleware.
|
|
193
203
|
|
|
194
204
|
Middleware run in the order they are defined by `.use()`. They are invoked
|
|
@@ -204,6 +214,7 @@ sequentially, requests start at the first middleware and work their way
|
|
|
204
214
|
| [...] | <code>function</code> |
|
|
205
215
|
|
|
206
216
|
**Example**
|
|
217
|
+
|
|
207
218
|
```javascript
|
|
208
219
|
// session middleware will run before authorize
|
|
209
220
|
router
|
|
@@ -218,9 +229,11 @@ router.use(['/users', '/admin'], userAuth());
|
|
|
218
229
|
|
|
219
230
|
app.use(router.routes());
|
|
220
231
|
```
|
|
232
|
+
|
|
221
233
|
<a name="module_egg-router--Router+prefix"></a>
|
|
222
234
|
|
|
223
235
|
#### router.prefix(prefix) ⇒ <code>Router</code>
|
|
236
|
+
|
|
224
237
|
Set the path prefix for a Router instance that was already initialized.
|
|
225
238
|
|
|
226
239
|
**Kind**: instance method of <code>[Router](#exp_module_egg-router--Router)</code>
|
|
@@ -230,12 +243,15 @@ Set the path prefix for a Router instance that was already initialized.
|
|
|
230
243
|
| prefix | <code>String</code> |
|
|
231
244
|
|
|
232
245
|
**Example**
|
|
246
|
+
|
|
233
247
|
```javascript
|
|
234
248
|
router.prefix('/things/:thing_id')
|
|
235
249
|
```
|
|
250
|
+
|
|
236
251
|
<a name="module_egg-router--Router+allowedMethods"></a>
|
|
237
252
|
|
|
238
253
|
#### router.allowedMethods([options]) ⇒ <code>function</code>
|
|
254
|
+
|
|
239
255
|
Returns separate middleware for responding to `OPTIONS` requests with
|
|
240
256
|
an `Allow` header containing the allowed methods, as well as responding
|
|
241
257
|
with `405 Method Not Allowed` and `501 Not Implemented` as appropriate.
|
|
@@ -250,6 +266,7 @@ with `405 Method Not Allowed` and `501 Not Implemented` as appropriate.
|
|
|
250
266
|
| [options.methodNotAllowed] | <code>function</code> | throw the returned value in place of the default MethodNotAllowed error |
|
|
251
267
|
|
|
252
268
|
**Example**
|
|
269
|
+
|
|
253
270
|
```javascript
|
|
254
271
|
var Koa = require('koa');
|
|
255
272
|
var Router = require('egg-router');
|
|
@@ -278,9 +295,11 @@ app.use(router.allowedMethods({
|
|
|
278
295
|
methodNotAllowed: () => new Boom.methodNotAllowed()
|
|
279
296
|
}));
|
|
280
297
|
```
|
|
298
|
+
|
|
281
299
|
<a name="module_egg-router--Router+redirect"></a>
|
|
282
300
|
|
|
283
301
|
#### router.redirect(source, destination, [code]) ⇒ <code>Router</code>
|
|
302
|
+
|
|
284
303
|
Redirect `source` to `destination` URL with optional 30x status `code`.
|
|
285
304
|
|
|
286
305
|
Both `source` and `destination` can be route names.
|
|
@@ -309,6 +328,7 @@ router.all('/login', ctx => {
|
|
|
309
328
|
<a name="module_egg-router--Router+route"></a>
|
|
310
329
|
|
|
311
330
|
#### router.route(name) ⇒ <code>Layer</code> | <code>false</code>
|
|
331
|
+
|
|
312
332
|
Lookup route with given `name`.
|
|
313
333
|
|
|
314
334
|
**Kind**: instance method of <code>[Router](#exp_module_egg-router--Router)</code>
|
|
@@ -320,6 +340,7 @@ Lookup route with given `name`.
|
|
|
320
340
|
<a name="module_egg-router--Router+url"></a>
|
|
321
341
|
|
|
322
342
|
#### router.url(name, params, [options]) ⇒ <code>String</code> | <code>Error</code>
|
|
343
|
+
|
|
323
344
|
Generate URL for route. Takes a route name and map of named `params`.
|
|
324
345
|
|
|
325
346
|
**Kind**: instance method of <code>[Router](#exp_module_egg-router--Router)</code>
|
|
@@ -332,6 +353,7 @@ Generate URL for route. Takes a route name and map of named `params`.
|
|
|
332
353
|
| [options.query] | <code>Object</code> | <code>String</code> | query options |
|
|
333
354
|
|
|
334
355
|
**Example**
|
|
356
|
+
|
|
335
357
|
```javascript
|
|
336
358
|
router.get('user', '/users/:id', (ctx, next) => {
|
|
337
359
|
// ...
|
|
@@ -354,9 +376,11 @@ router.url('user', { id: 3 }, { query: { limit: 1 } });
|
|
|
354
376
|
router.url('user', { id: 3 }, { query: "limit=1" });
|
|
355
377
|
// => "/users/3?limit=1"
|
|
356
378
|
```
|
|
379
|
+
|
|
357
380
|
<a name="module_egg-router--Router+param"></a>
|
|
358
381
|
|
|
359
382
|
#### router.param(param, middleware) ⇒ <code>Router</code>
|
|
383
|
+
|
|
360
384
|
Run middleware for named route parameters. Useful for auto-loading or
|
|
361
385
|
validation.
|
|
362
386
|
|
|
@@ -368,6 +392,7 @@ validation.
|
|
|
368
392
|
| middleware | <code>function</code> |
|
|
369
393
|
|
|
370
394
|
**Example**
|
|
395
|
+
|
|
371
396
|
```javascript
|
|
372
397
|
router
|
|
373
398
|
.param('user', (id, ctx, next) => {
|
|
@@ -386,9 +411,11 @@ router
|
|
|
386
411
|
// /users/3 => {"id": 3, "name": "Alex"}
|
|
387
412
|
// /users/3/friends => [{"id": 4, "name": "TJ"}]
|
|
388
413
|
```
|
|
414
|
+
|
|
389
415
|
<a name="module_egg-router--Router.url"></a>
|
|
390
416
|
|
|
391
417
|
#### Router.url(path, params [, options]) ⇒ <code>String</code>
|
|
418
|
+
|
|
392
419
|
Generate URL from url pattern and given `params`.
|
|
393
420
|
|
|
394
421
|
**Kind**: static method of <code>[Router](#exp_module_egg-router--Router)</code>
|
|
@@ -401,6 +428,7 @@ Generate URL from url pattern and given `params`.
|
|
|
401
428
|
| [options.query] | <code>Object</code> | <code>String</code> | query options |
|
|
402
429
|
|
|
403
430
|
**Example**
|
|
431
|
+
|
|
404
432
|
```javascript
|
|
405
433
|
var url = Router.url('/users/:id', {id: 1});
|
|
406
434
|
// => "/users/1"
|
|
@@ -412,3 +440,7 @@ const url = Router.url('/users/:id', {id: 1}, {query: { active: true }});
|
|
|
412
440
|
## Tests
|
|
413
441
|
|
|
414
442
|
Run tests using `npm test`.
|
|
443
|
+
|
|
444
|
+
## License
|
|
445
|
+
|
|
446
|
+
[MIT](LICENSE)
|
package/lib/egg_router.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const is = require('is-type-of');
|
|
4
|
-
const Router = require('./router');
|
|
5
3
|
const utility = require('utility');
|
|
6
4
|
const inflection = require('inflection');
|
|
7
5
|
const assert = require('assert');
|
|
8
6
|
const utils = require('./utils');
|
|
7
|
+
const Router = require('./router');
|
|
9
8
|
|
|
10
9
|
const METHODS = [ 'head', 'options', 'get', 'put', 'patch', 'post', 'delete' ];
|
|
11
10
|
|
|
@@ -138,6 +137,7 @@ class EggRouter extends Router {
|
|
|
138
137
|
* @return {Router} return route object.
|
|
139
138
|
* @since 1.0.0
|
|
140
139
|
*/
|
|
140
|
+
|
|
141
141
|
resources(...args) {
|
|
142
142
|
const splited = spliteAndResolveRouterParams({ args, app: this.app });
|
|
143
143
|
const middlewares = splited.middlewares;
|
|
@@ -198,7 +198,7 @@ class EggRouter extends Router {
|
|
|
198
198
|
const args = params;
|
|
199
199
|
let url = route.path;
|
|
200
200
|
|
|
201
|
-
assert(!
|
|
201
|
+
assert(!(url instanceof RegExp), `Can't get the url for regExp ${url} for by name '${name}'`);
|
|
202
202
|
|
|
203
203
|
const queries = [];
|
|
204
204
|
if (typeof args === 'object' && args !== null) {
|
|
@@ -263,7 +263,7 @@ class EggRouter extends Router {
|
|
|
263
263
|
function spliteAndResolveRouterParams({ args, app }) {
|
|
264
264
|
let prefix;
|
|
265
265
|
let middlewares;
|
|
266
|
-
if (args.length >= 3 && (
|
|
266
|
+
if (args.length >= 3 && (typeof args[1] === 'string' || args[1] instanceof RegExp)) {
|
|
267
267
|
// app.get(name, url, [...middleware], controller)
|
|
268
268
|
prefix = args.slice(0, 2);
|
|
269
269
|
middlewares = args.slice(2);
|
|
@@ -285,7 +285,7 @@ function spliteAndResolveRouterParams({ args, app }) {
|
|
|
285
285
|
* @return {Function} controller function
|
|
286
286
|
*/
|
|
287
287
|
function resolveController(controller, app) {
|
|
288
|
-
if (
|
|
288
|
+
if (typeof controller === 'string') {
|
|
289
289
|
const actions = controller.split('.');
|
|
290
290
|
let obj = app.controller;
|
|
291
291
|
actions.forEach(key => {
|
package/lib/layer.js
CHANGED
package/lib/router.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* RESTful resource routing middleware for eggjs.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const debug = require('
|
|
7
|
+
const debug = require('util').debuglog('egg-router');
|
|
8
8
|
const compose = require('koa-compose');
|
|
9
9
|
const HttpError = require('http-errors');
|
|
10
10
|
const methods = require('methods');
|
package/lib/utils.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const convert = require('koa-convert');
|
|
4
|
-
const is = require('is-type-of');
|
|
5
4
|
const co = require('co');
|
|
6
5
|
|
|
6
|
+
function isGeneratorFunction(obj) {
|
|
7
|
+
return obj
|
|
8
|
+
&& obj.constructor
|
|
9
|
+
&& obj.constructor.name === 'GeneratorFunction';
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
module.exports = {
|
|
8
13
|
async callFn(fn, args, ctx) {
|
|
9
14
|
args = args || [];
|
|
10
|
-
if (
|
|
11
|
-
if (
|
|
15
|
+
if (typeof fn !== 'function') return;
|
|
16
|
+
if (isGeneratorFunction(fn)) fn = co.wrap(fn);
|
|
12
17
|
return ctx ? fn.call(ctx, ...args) : fn(...args);
|
|
13
18
|
},
|
|
14
19
|
|
|
15
20
|
middleware(fn) {
|
|
16
|
-
return
|
|
21
|
+
return isGeneratorFunction(fn) ? convert(fn) : fn;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
isGeneratorFunction,
|
|
25
|
+
isAsyncFunction(obj) {
|
|
26
|
+
return obj
|
|
27
|
+
&& obj.constructor
|
|
28
|
+
&& obj.constructor.name === 'AsyncFunction';
|
|
29
|
+
},
|
|
30
|
+
isPromise(obj) {
|
|
31
|
+
return obj
|
|
32
|
+
&& typeof obj.then === 'function';
|
|
17
33
|
},
|
|
18
34
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/router",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">= 8.5.0"
|
|
6
|
+
},
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"tag": "latest-2"
|
|
10
|
+
},
|
|
4
11
|
"description": "Router middleware for egg/koa. Provides RESTful resource routing.",
|
|
5
12
|
"repository": {
|
|
6
13
|
"type": "git",
|
|
7
|
-
"url": "
|
|
14
|
+
"url": "git@github.com:eggjs/router.git"
|
|
8
15
|
},
|
|
9
16
|
"bugs": {
|
|
10
17
|
"url": "https://github.com/eggjs/egg/issues"
|
|
@@ -22,20 +29,17 @@
|
|
|
22
29
|
],
|
|
23
30
|
"dependencies": {
|
|
24
31
|
"co": "^4.6.0",
|
|
25
|
-
"debug": "^3.1.0",
|
|
26
32
|
"http-errors": "^1.3.1",
|
|
27
33
|
"inflection": "^1.12.0",
|
|
28
|
-
"is-type-of": "^1.2.1",
|
|
29
34
|
"koa-compose": "^3.0.0",
|
|
30
35
|
"koa-convert": "^1.2.0",
|
|
31
36
|
"methods": "^1.0.1",
|
|
32
|
-
"path-to-regexp": "^1.
|
|
37
|
+
"path-to-regexp": "^1.9.0",
|
|
33
38
|
"urijs": "^1.19.0",
|
|
34
39
|
"utility": "^1.15.0"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {
|
|
37
42
|
"egg-bin": "^4.10.0",
|
|
38
|
-
"egg-ci": "^1.11.0",
|
|
39
43
|
"eslint": "^5.13.0",
|
|
40
44
|
"eslint-config-egg": "^7.1.0",
|
|
41
45
|
"expect.js": "^0.3.1",
|
|
@@ -50,12 +54,5 @@
|
|
|
50
54
|
"ci": "npm run lint && egg-bin cov",
|
|
51
55
|
"lint": "eslint ."
|
|
52
56
|
},
|
|
53
|
-
"ci": {
|
|
54
|
-
"type": "github",
|
|
55
|
-
"version": "8, 10, 11"
|
|
56
|
-
},
|
|
57
|
-
"engines": {
|
|
58
|
-
"node": ">= 8"
|
|
59
|
-
},
|
|
60
57
|
"license": "MIT"
|
|
61
58
|
}
|
package/History.md
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
2.0.1 / 2021-07-12
|
|
3
|
-
==================
|
|
4
|
-
|
|
5
|
-
**fixes**
|
|
6
|
-
* [[`2c44ec0`](http://github.com/eggjs/egg-router/commit/2c44ec0bdeff1e8f46d899ed4386d1e28a93a854)] - fix: ensure ctx._matchedRoute and ctx._matchedRouteName to be correct (#7) (Yiyu He <<dead_horse@qq.com>>)
|
|
7
|
-
|
|
8
|
-
2.0.0 / 2019-02-14
|
|
9
|
-
==================
|
|
10
|
-
|
|
11
|
-
**features**
|
|
12
|
-
* [[`f0b29ec`](https://github.com/eggjs/egg-router/commit/f0b29ec34df32ba9d872f6318f4febd2b4ef9359)] - refactor: use class instead prototype (#4) (fengmk2 <<fengmk2@gmail.com>>)
|
|
13
|
-
|
|
14
|
-
1.2.0 / 2019-02-13
|
|
15
|
-
==================
|
|
16
|
-
|
|
17
|
-
**features**
|
|
18
|
-
* [[`1a0036a`](http://github.com/eggjs/egg-router/commit/1a0036a64a023b6b7993fecffe8062d5d0150971)] - feat: add routerPath to respond to routerName (#2) (Khaidi Chu <<i@2333.moe>>)
|
|
19
|
-
|
|
20
|
-
**others**
|
|
21
|
-
* [[`ff723fd`](http://github.com/eggjs/egg-router/commit/ff723fd03630ec49d5fe861abf129a583d214d22)] - chore: add koa-router license (#3) (fengmk2 <<fengmk2@gmail.com>>)
|
|
22
|
-
|
|
23
|
-
1.1.0 / 2019-01-30
|
|
24
|
-
==================
|
|
25
|
-
|
|
26
|
-
**features**
|
|
27
|
-
* [[`b318dd5`](http://github.com/eggjs/egg-router/commit/b318dd5ff2eea60013ed62b2a435f803c12bf20f)] - feat: add egg-router (dead-horse <<dead_horse@qq.com>>)
|
|
28
|
-
|
|
29
|
-
**fixes**
|
|
30
|
-
* [[`b3db7b4`](http://github.com/eggjs/egg-router/commit/b3db7b41988d3bf1b4e885ed76b3a8165c1d3b1d)] - fix: add missing dependencies koa-convert (dead-horse <<dead_horse@qq.com>>)
|
|
31
|
-
* [[`c280336`](http://github.com/eggjs/egg-router/commit/c2803368a8256bc9504ae3c821eefeb9d1fcbc4d)] - fix: only support node@8 (dead-horse <<dead_horse@qq.com>>)
|
|
32
|
-
* [[`7a887a2`](http://github.com/eggjs/egg-router/commit/7a887a252445e602c2ea7e1c6f4cde52a433644d)] - fix: update license (dead-horse <<dead_horse@qq.com>>)
|
|
33
|
-
|
|
34
|
-
**others**
|
|
35
|
-
* [[`ae40168`](http://github.com/eggjs/egg-router/commit/ae4016862fb8bdaf30e730a9278fbb1455d8b75d)] - docs: clean doc (dead-horse <<dead_horse@qq.com>>)
|
|
36
|
-
* [[`e4f21a8`](http://github.com/eggjs/egg-router/commit/e4f21a8ed6dfd72c4d6f4a13bbda9a4e90b0401c)] - chore: fix history (dead-horse <<dead_horse@qq.com>>)
|
|
37
|
-
|
|
38
|
-
1.0.0 / 2019-01-30
|
|
39
|
-
==================
|
|
40
|
-
|
|
41
|
-
**others**
|
|
42
|
-
* [[`d6496e0`](http://github.com/eggjs/egg-router/commit/d6496e09be6b0f91dcb96611f31ec5ab6ad8ac78)] - refactor: rename to @eggjs/router (dead-horse <<dead_horse@qq.com>>)
|
|
43
|
-
|
|
44
|
-
-------------------------------
|
|
45
|
-
|
|
46
|
-
# Release History from koa-router
|
|
47
|
-
|
|
48
|
-
## 7.4.0
|
|
49
|
-
|
|
50
|
-
- Fix router.url() for multiple nested routers [#407](https://github.com/alexmingoia/koa-router/pull/407)
|
|
51
|
-
- `layer.name` added to `ctx` at `ctx.routerName` during routing [#412](https://github.com/alexmingoia/koa-router/pull/412)
|
|
52
|
-
- Router.use() was erroneously settings `(.*)` as a prefix to all routers nested with .use that did not pass an explicit prefix string as the first argument. This resulted in routes being matched that should not have been, included the running of multiple route handlers in error. [#369](https://github.com/alexmingoia/koa-router/issues/369) and [#410](https://github.com/alexmingoia/koa-router/issues/410) include information on this issue.
|
|
53
|
-
|
|
54
|
-
## 7.3.0
|
|
55
|
-
|
|
56
|
-
- Router#url() now accepts query parameters to add to generated urls [#396](https://github.com/alexmingoia/koa-router/pull/396)
|
|
57
|
-
|
|
58
|
-
## 7.2.1
|
|
59
|
-
|
|
60
|
-
- Respond to CORS preflights with 200, 0 length body [#359](https://github.com/alexmingoia/koa-router/issues/359)
|
|
61
|
-
|
|
62
|
-
## 7.2.0
|
|
63
|
-
|
|
64
|
-
- Fix a bug in Router#url and append Router object to ctx. [#350](https://github.com/alexmingoia/koa-router/pull/350)
|
|
65
|
-
- Adds `_matchedRouteName` to context [#337](https://github.com/alexmingoia/koa-router/pull/337)
|
|
66
|
-
- Respond to CORS preflights with 200, 0 length body [#359](https://github.com/alexmingoia/koa-router/issues/359)
|
|
67
|
-
|
|
68
|
-
## 7.1.1
|
|
69
|
-
|
|
70
|
-
- Fix bug where param handlers were run out of order [#282](https://github.com/alexmingoia/koa-router/pull/282)
|
|
71
|
-
|
|
72
|
-
## 7.1.0
|
|
73
|
-
|
|
74
|
-
- Backports: merge 5.4 work into the 7.x upstream. See 5.4.0 updates for more details.
|
|
75
|
-
|
|
76
|
-
## 7.0.1
|
|
77
|
-
|
|
78
|
-
- Fix: allowedMethods should be ctx.method not this.method [#215](https://github.com/alexmingoia/koa-router/pull/215)
|
|
79
|
-
|
|
80
|
-
## 7.0.0
|
|
81
|
-
|
|
82
|
-
- The API has changed to match the new promise-based middleware
|
|
83
|
-
signature of koa 2. See the
|
|
84
|
-
[koa 2.x readme](https://github.com/koajs/koa/tree/2.0.0-alpha.3) for more
|
|
85
|
-
information.
|
|
86
|
-
- Middleware is now always run in the order declared by `.use()` (or `.get()`,
|
|
87
|
-
etc.), which matches Express 4 API.
|
|
88
|
-
|
|
89
|
-
## 5.4.0
|
|
90
|
-
|
|
91
|
-
- Expose matched route at `ctx._matchedRoute`.
|
|
92
|
-
|
|
93
|
-
## 5.3.0
|
|
94
|
-
|
|
95
|
-
- Register multiple routes with array of paths [#203](https://github.com/alexmingoia/koa-router/issue/143).
|
|
96
|
-
- Improved router.url() [#143](https://github.com/alexmingoia/koa-router/pull/143)
|
|
97
|
-
- Adds support for named routes and regular expressions
|
|
98
|
-
[#152](https://github.com/alexmingoia/koa-router/pull/152)
|
|
99
|
-
- Add support for custom throw functions for 405 and 501 responses [#206](https://github.com/alexmingoia/koa-router/pull/206)
|
|
100
|
-
|
|
101
|
-
## 5.2.3
|
|
102
|
-
|
|
103
|
-
- Fix for middleware running twice when nesting routes [#184](https://github.com/alexmingoia/koa-router/issues/184)
|
|
104
|
-
|
|
105
|
-
## 5.2.2
|
|
106
|
-
|
|
107
|
-
- Register routes without params before those with params [#183](https://github.com/alexmingoia/koa-router/pull/183)
|
|
108
|
-
- Fix for allowed methods [#182](https://github.com/alexmingoia/koa-router/issues/182)
|
|
109
|
-
|
|
110
|
-
## 5.2.0
|
|
111
|
-
|
|
112
|
-
- Add support for async/await. Resolves [#130](https://github.com/alexmingoia/koa-router/issues/130).
|
|
113
|
-
- Add support for array of paths by Router#use(). Resolves [#175](https://github.com/alexmingoia/koa-router/issues/175).
|
|
114
|
-
- Inherit param middleware when nesting routers. Fixes [#170](https://github.com/alexmingoia/koa-router/issues/170).
|
|
115
|
-
- Default router middleware without path to root. Fixes [#161](https://github.com/alexmingoia/koa-router/issues/161), [#155](https://github.com/alexmingoia/koa-router/issues/155), [#156](https://github.com/alexmingoia/koa-router/issues/156).
|
|
116
|
-
- Run nested router middleware after parent's. Fixes [#156](https://github.com/alexmingoia/koa-router/issues/156).
|
|
117
|
-
- Remove dependency on koa-compose.
|
|
118
|
-
|
|
119
|
-
## 5.1.1
|
|
120
|
-
|
|
121
|
-
- Match routes in order they were defined. Fixes #131.
|
|
122
|
-
|
|
123
|
-
## 5.1.0
|
|
124
|
-
|
|
125
|
-
- Support mounting router middleware at a given path.
|
|
126
|
-
|
|
127
|
-
## 5.0.1
|
|
128
|
-
|
|
129
|
-
- Fix bug with missing parameters when nesting routers.
|
|
130
|
-
|
|
131
|
-
## 5.0.0
|
|
132
|
-
|
|
133
|
-
- Remove confusing API for extending koa app with router methods. Router#use()
|
|
134
|
-
does not have the same behavior as app#use().
|
|
135
|
-
- Add support for nesting routes.
|
|
136
|
-
- Remove support for regular expression routes to achieve nestable routers and
|
|
137
|
-
enable future trie-based routing optimizations.
|
|
138
|
-
|
|
139
|
-
## 4.3.2
|
|
140
|
-
|
|
141
|
-
- Do not send 405 if route matched but status is 404. Fixes #112, closes #114.
|
|
142
|
-
|
|
143
|
-
## 4.3.1
|
|
144
|
-
|
|
145
|
-
- Do not run middleware if not yielded to by previous middleware. Fixes #115.
|
|
146
|
-
|
|
147
|
-
## 4.3.0
|
|
148
|
-
|
|
149
|
-
- Add support for router prefixes.
|
|
150
|
-
- Add MIT license.
|
|
151
|
-
|
|
152
|
-
## 4.2.0
|
|
153
|
-
|
|
154
|
-
- Fixed issue with router middleware being applied even if no route was
|
|
155
|
-
matched.
|
|
156
|
-
- Router.url - new static method to generate url from url pattern and data
|
|
157
|
-
|
|
158
|
-
## 4.1.0
|
|
159
|
-
|
|
160
|
-
Private API changed to separate context parameter decoration from route
|
|
161
|
-
matching. `Router#match` and `Route#match` are now pure functions that return
|
|
162
|
-
an array of routes that match the URL path.
|
|
163
|
-
|
|
164
|
-
For modules using this private API that need to determine if a method and path
|
|
165
|
-
match a route, `route.methods` must be checked against the routes returned from
|
|
166
|
-
`router.match()`:
|
|
167
|
-
|
|
168
|
-
```javascript
|
|
169
|
-
var matchedRoute = router.match(path).filter(function (route) {
|
|
170
|
-
return ~route.methods.indexOf(method);
|
|
171
|
-
}).shift();
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
## 4.0.0
|
|
175
|
-
|
|
176
|
-
405, 501, and OPTIONS response handling was moved into separate middleware
|
|
177
|
-
`router.allowedMethods()`. This resolves incorrect 501 or 405 responses when
|
|
178
|
-
using multiple routers.
|
|
179
|
-
|
|
180
|
-
### Breaking changes
|
|
181
|
-
|
|
182
|
-
4.x is mostly backwards compatible with 3.x, except for the following:
|
|
183
|
-
|
|
184
|
-
- Instantiating a router with `new` and `app` returns the router instance,
|
|
185
|
-
whereas 3.x returns the router middleware. When creating a router in 4.x, the
|
|
186
|
-
only time router middleware is returned is when creating using the
|
|
187
|
-
`Router(app)` signature (with `app` and without `new`).
|