我有这个代码
const keren = async (ctx: Context, next: any) => {
console.log('keren');
await next();
}
const mantap = async (ctx: Context, next: any) => {
console.log('mantap');
await next();
}
router.get('/owkowkkow',keren,mantap,(ctx: Context) => {
ctx.response.body = "wkwkwkw";
});
它工作很好,但我想在一个名为 Onevar 的变量中使用 keren 和 mantap
所以代码将是这样的:
router.get('/owkowkkow',onevar,(ctx: Context) => {
ctx.response.body = "wkwkwkw";
});
怎么做?可以吗?
Oak 附带compose
中间件,允许您从多个中间件组成中间件
import { composeMiddleware as compose } from "https://deno.land/x/oak/mod.ts";
const onevar = compose([
async (ctx: Context, next: any) => {
console.log('keren');
await next();
},
async (ctx: Context, next: any) => {
console.log('mantap');
await next();
}
])
router.get('/owkowkkow',onevar,(ctx: Context) => {
ctx.response.body = "wkwkwkw";
});