我有这个密码
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";
});
怎么做? 是罐头吗?
在Express和其他框架上,您可以传递一组中间件:
const onevar = [
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";
});