hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
https://www.npmjs.com/package/next-connect
MIT License
1.64k stars 65 forks source link

How to use async with #130

Closed ajjack50n closed 3 years ago

ajjack50n commented 3 years ago

Hey can someone show me how to use async with ...

const handler = nc({ attachParams: true });

handler.get("/users/:userId/posts/:postId", (req, res) => {
  // Visiting '/users/12/posts/23' will render '{"userId":"12","postId":"23"}'
  res.send(req.params);
});

I don't seem to be able to make this work. I want to use await when calling Sequelize with the handler.

ajjack50n commented 3 years ago

ignore.. solution obvious!:)

handler.get("/users/:userId/posts/:postId", async (req, res) => {
  // Visiting '/users/12/posts/23' will render '{"userId":"12","postId":"23"}'
  res.send(req.params);
});