Is the koa2 path data correct or 404?

koa2 path data is correct or 404
and await is not allowed in the function. Without await, you can

router.prefix("/post")

router.get("/list",Post.list);
exports.list = async(ctx, next)=>{
    let keyword,query,result=[];

    if( ctx.query.keyword){
       keyword = ctx.query.keyword; 
       query = Post.find({
        $or:[{
            title: /.*${keyword}.*/i,
            body: /.*${keyword}.*/i
        }]
        },
        "title category tags createAt updateAt _id");
    }else{
         query = Post.find({},"title category tags createAt updateAt  _id");
    }
    
    
    result= await dbHelper.Exec(query);   
    console.log(`result:${result}`)//
    ctx.body = result; //  ctx.response.body = result;
    console.log(ctx) // 

}

Aug.16,2021

simplify other code and try the following 404?

const Router = require('koa-router');
const router = new Router({prefix:'/post'});

router.get('/list',async(ctx,next)=>{
    ctx.body = '123';
});

it's strange to add await next () to a middleware. Does this middleware add await to something that doesn't provide me with the next service?

Menu