diff --git a/decorator/decorator.ts b/decorator/decorator.ts index f2568ee..4abbe62 100644 --- a/decorator/decorator.ts +++ b/decorator/decorator.ts @@ -32,7 +32,7 @@ const consumeRoutes: ClassDecorator = (target: Function) => { const router = getRouterInitial(); const path = target.prototype.decorator_prefix_min || ''; getRoutes().forEach(val => { - router[val.method](path + val.path, val.handler, val.middleware.concat(getMiddlewares())); + router[val.method](path + val.path, val.handler, getMiddlewares().concat(val.middleware)); }); clearMiddlewares(); clearRoutes(); diff --git a/decorator/decorator.type.ts b/decorator/decorator.type.ts index 6d7850c..f7b32e7 100644 --- a/decorator/decorator.type.ts +++ b/decorator/decorator.type.ts @@ -1,7 +1,7 @@ import {Middleware} from "./middleware.ts"; import {DecorationApplication} from "./application.ts"; import {Router} from "./router.ts"; -import {ListenOptions, ReqMethod, MethodFuncArgument} from "../model.ts"; +import {ListenOptions, ReqMethod, MiddlewareFunc, MethodFuncArgument} from "../model.ts"; export declare type Entity = { app: DecorationApplication | null, @@ -11,7 +11,7 @@ export declare type Entity = { routes: Array<{ path: string; method: ReqMethod, - middleware: Function[], + middleware: MiddlewareFunc[], handler: Function, }>; middlewares: MethodFuncArgument; diff --git a/examples/decorator/demo2/routes/route1.ts b/examples/decorator/demo2/routes/route1.ts index 25a06e9..e271e11 100644 --- a/examples/decorator/demo2/routes/route1.ts +++ b/examples/decorator/demo2/routes/route1.ts @@ -10,7 +10,10 @@ class Route1 { await next(); console.log('route1 middle end'); } - @Get('/test') + @Get('/test', [async (req: Req, res: Res, next: Function) => { + console.log('route1 middle for /test'); + await next(); + }]) test(req: Req, res: Res) { res.body = { url: 'route1 test' diff --git a/examples/decorator/demo2/routes/route2.ts b/examples/decorator/demo2/routes/route2.ts index a9d77d3..ec7b84c 100644 --- a/examples/decorator/demo2/routes/route2.ts +++ b/examples/decorator/demo2/routes/route2.ts @@ -12,7 +12,10 @@ class Route2 { await next(); console.log('route2 middle end'); } - @Get('/test') + @Get('/test', [async (req: Req, res: Res, next: Function) => { + console.log('route2 middle for /test'); + await next(); + }]) test(req: Req, res: Res) { res.body = { prefix: '/route2'