instantcommerce / next-api-decorators

Collection of decorators to create typed Next.js API routes, with easy request validation and transformation.
https://next-api-decorators.vercel.app
MIT License
412 stars 29 forks source link

2.0.1-beta.1 does not work on Windows #486

Closed stevemu closed 1 year ago

stevemu commented 1 year ago

When I use 2.0.1-beta.1 on Windows, I got following error:

error stack:

{"name":"TypeError","message":"Cannot read property 'replace' of undefined","stack":"TypeError: Cannot read property 'replace' of undefined\n    at Object.parseRequestUrl (D:\\Users\\user\\work\\my-project\\node_modules\\next-api-decorators\\dist\\internals\\parseRequestUrl.js:20:41)\n    at D:\\Users\\user\\work\\my-project\\node_modules\\next-api-decorators\\dist\\createHandler.js:35:40\n    at Object.apiResolver (D:\\Users\\user\\work\\my-project\\node_modules\\next\\dist\\server\\api-utils\\node.js:185:15)\n    at processTicksAndRejections (internal/process/task_queues.js:93:5)\n    at async DevServer.runApi (D:\\Users\\user\\work\\my-project\\node_modules\\next\\dist\\server\\next-server.js:395:9)\n    at async Object.fn (D:\\Users\\user\\work\\my-project\\node_modules\\next\\dist\\server\\base-server.js:496:37)\n    at async Router.execute (D:\\Users\\user\\work\\my-project\\node_modules\\next\\dist\\server\\router.js:226:36)\n    at async DevServer.run (D:\\Users\\user\\work\\my-project\\node_modules\\next\\dist\\server\\base-server.js:606:29)\n    at async DevServer.run (D:\\Users\\user\\work\\my-project\\node_modules\\next\\dist\\server\\dev\\next-dev-server.js:450:20)\n    at async DevServer.handleRequest (D:\\Users\\user\\work\\my-project\\node_modules\\next\\dist\\server\\base-server.js:321:20)"},

I think it is due to the line https://github.com/instantcommerce/next-api-decorators/blob/beta/lib/internals/parseRequestUrl.ts#L22 here didn't consider the Windows style directoryPath.

In Windows, directoryPath is like: \\pages\\api\\my-api,
In Mac, directoryPath is like: /pages/api/my-sapi,

I think directoryPath.split('/pages') does not work for the Windows directoryPath.

I love next-api-decorators, thank you.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 2.0.1-beta.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

stevemu commented 1 year ago

thank you for the quick fix!!

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 2.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: