Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update middle scope works #37

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion decorator/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions decorator/decorator.type.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -11,7 +11,7 @@ export declare type Entity = {
routes: Array<{
path: string;
method: ReqMethod,
middleware: Function[],
middleware: MiddlewareFunc[],
handler: Function,
}>;
middlewares: MethodFuncArgument;
Expand Down
5 changes: 4 additions & 1 deletion examples/decorator/demo2/routes/route1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 4 additions & 1 deletion examples/decorator/demo2/routes/route2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down