Merge pull request #10593 from jtmthf/master

Fixed param middleware to accept url param as first middleware param
This commit is contained in:
Nathan Shively-Sanders
2016-08-12 10:16:30 -07:00
committed by GitHub
2 changed files with 13 additions and 6 deletions
+4 -1
View File
@@ -11,6 +11,9 @@ const router = new Router({
});
router
.param('id', function(id, ctx, next) {
next();
})
.get('/', function (ctx, next) {
ctx.body = 'Hello World!';
})
@@ -23,7 +26,7 @@ router
.del('/users/:id', function (ctx, next) {
// ...
});
router.get('user', '/users/:id', function (ctx, next) {
ctx.body = "sdsd";
});
+9 -5
View File
@@ -30,7 +30,7 @@ declare module "koa-router" {
export interface IRouterOptions {
/**
* Router prefixes
* Router prefixes
*/
prefix?: string;
/**
@@ -52,6 +52,10 @@ declare module "koa-router" {
(ctx: Router.IRouterContext, next?: () => any): any;
}
export interface IParamMiddleware {
(param: string, ctx: Router.IRouterContext, next?: () => any): any;
}
export interface IRouterAllowedMethodsOptions {
/**
* throw error instead of setting status and header
@@ -141,13 +145,13 @@ declare module "koa-router" {
*/
get(name: string, path: string, ...middleware: Array<Router.IMiddleware>): Router;
get(path: string, ...middleware: Array<Router.IMiddleware>): Router;
/**
* HTTP post method
*/
post(name: string, path: string, ...middleware: Array<Router.IMiddleware>): Router;
post(path: string, ...middleware: Array<Router.IMiddleware>): Router;
/**
* HTTP put method
*/
@@ -214,7 +218,7 @@ declare module "koa-router" {
/**
* Redirect `source` to `destination` URL with optional 30x status `code`.
*
*
* Both `source` and `destination` can be route names.
*/
redirect(source: string, destination: string, code?: number): Router;
@@ -245,7 +249,7 @@ declare module "koa-router" {
/**
* Run middleware for named route parameters. Useful for auto-loading or validation.
*/
param(param: string, middleware: Router.IMiddleware): Router;
param(param: string, middleware: Router.IParamMiddleware): Router;
/**
* Generate URL from url pattern and given `params`.