0

With next-connect version 0.13 I used a factory pattern to create router middle-ware for all endpoints.

export default function handler() {
  return nc()
    .use(async (req, res, next) => {
      await dbConnect(MONGODB_URI);
      await next();
    })
    .post(authSession); // secure all POST requests
}

Which was used in API endpoints like below.

export default handler()
  .use(getCachedData)
  .get(async (req, res) => {
     res.status(200).json(req.cached.data);
});

After upgrading to next-connect v1 I am not able to get this working. Could not find any documentation and the repo already has unanswered questions about the topic. My goal is to have a middleware function for the database connection, security and some caching. Any suggestions?

nordic70
  • 130
  • 2
  • 9

0 Answers0