0

I found a demo in the koa-router official docs.

router.get(
  '/users/:id',
  (ctx, next) => {
    //something
  },
  async ctx => {
    //I can't use await here
  }
);

But why can't I use async and await in the second middleware? I always got Not found response by default.

  • Who or what is saying you can't use it? If you are saying you got some kind of "not found" error when you tried it, then what exactly was the error, and what led you to believe that it's something to do with `await`? – Noah Jul 26 '21 at 15:03
  • 1
    Thank you @Noah for your comment. I'v known what happend. I use only `next()` in the first middleware instead of `await next()` . So the request didn't wait for my db operation to response to the client. – Smile Gh Jul 27 '21 at 01:47

0 Answers0