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

[Feature request] method `.scope` to set endpoint scope. #138

Closed TERADA-DANTE closed 3 years ago

TERADA-DANTE commented 3 years ago

Good day! :) I am a big fan of this package and want to PR but due to the lack of acknowledge, I couldn't.

Here is my scenario.

// Let's say I have divided callbacks in another dir.
export default handler
  .use("/api/interviews", middleware.logger)
  .get("/api/interviews", interviews.service.findMany)
  .use("/api/interviews/:id", interviews.middleware.validator)
  .get("/api/interviews/:id", interviews.service.findUnique)

I have to write all the directories every time I have to reach.

What if there is kind of .scope method so that user can control the base ? like,

export default handler.scope("/api/interviews")
  .use("/", middleware.logger)
  .get("/", interviews.service.findMany)
  .use("/:id", interviews.middleware.validator)
  .get("/:id", interviews.service.findUnique)
// Change base
 .scope("/api/users")
 .get(...)

I have tried to look into node_modules but I guess It's out of my hand.

hoangvvo commented 3 years ago

Hey @TERADA-DANTE, I understood your use case but was wondering whether you use it in Next.js.

hoangvvo commented 3 years ago

@TERADA-DANTE I just realized this issue was closed!

Did you resolve the issue? I think my question was confusing. What I meant was that if you are using Next.js, define all the route in pages/api/test.js like

handler.get(() => {}).post(() => {});

may achieve the same purpose.

TERADA-DANTE commented 3 years ago

@hoangvvo Hi. Thank you for your support. Your suggestion fits quite well to my purpose. Thanks :)