From c348d970d54ad7910ab9c21368134794279773f9 Mon Sep 17 00:00:00 2001 From: Moore Date: Fri, 12 Aug 2016 11:03:55 -0500 Subject: [PATCH 1/2] Fixed param middleware to accept url param as first middleware param --- koa-router/koa-router-tests.ts | 6 +++++- koa-router/koa-router.d.ts | 14 +++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/koa-router/koa-router-tests.ts b/koa-router/koa-router-tests.ts index deaa7e083d..2adb278ed1 100644 --- a/koa-router/koa-router-tests.ts +++ b/koa-router/koa-router-tests.ts @@ -1,5 +1,6 @@ /// /// +/// import * as Koa from "koa"; import * as Router from "koa-router"; @@ -11,6 +12,9 @@ const router = new Router({ }); router + .param('id', function(id, ctx, next) { + next(); + }) .get('/', function (ctx, next) { ctx.body = 'Hello World!'; }) @@ -23,7 +27,7 @@ router .del('/users/:id', function (ctx, next) { // ... }); - + router.get('user', '/users/:id', function (ctx, next) { ctx.body = "sdsd"; }); diff --git a/koa-router/koa-router.d.ts b/koa-router/koa-router.d.ts index d289657c84..25ec962dad 100644 --- a/koa-router/koa-router.d.ts +++ b/koa-router/koa-router.d.ts @@ -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; get(path: string, ...middleware: Array): Router; - + /** * HTTP post method */ post(name: string, path: string, ...middleware: Array): Router; post(path: string, ...middleware: Array): 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`. From e630a5756bed554f8b93ce5483ba54bd88003ebe Mon Sep 17 00:00:00 2001 From: Moore Date: Fri, 12 Aug 2016 12:15:42 -0500 Subject: [PATCH 2/2] Removed uneeded reference --- koa-router/koa-router-tests.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/koa-router/koa-router-tests.ts b/koa-router/koa-router-tests.ts index 2adb278ed1..36d3e6c1c8 100644 --- a/koa-router/koa-router-tests.ts +++ b/koa-router/koa-router-tests.ts @@ -1,6 +1,5 @@ /// /// -/// import * as Koa from "koa"; import * as Router from "koa-router";