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.62k stars 65 forks source link

.clone() returns a new instance but can not produce .handler() #206

Closed BounSweFerhatSal closed 1 year ago

BounSweFerhatSal commented 1 year ago

when creating a router as below in a separate file , to use as a base as below :

import { createRouter } from "next-connect";

const pipeLineRouter = createRouter();
export default pipeLineRouter
  .use(jwtTokenValidator_middleware)
  .use(dbConnection_middleware);

then importing in another API file by cloning the router as below (as suggested) :

import apiPipeline from "/lib/apiPipeline";

const router = apiPipeline.clone();
router.get(async (req, res) => {
    //......
});

export default router.handler(errorCather);

router.handler() fails with error :

TypeError: router.handler is not a function

However, console.log(router) gives exact same router object properties which has been cloned.

hoangvvo commented 1 year ago

This is a bug, I am fixing it right now

hoangvvo commented 1 year ago

This is fixed in latest next version. Let me know if you still face it.