kartikk221 / hyper-express

High performance Node.js webserver with a simple-to-use API powered by uWebsockets.js under the hood.
MIT License
1.73k stars 89 forks source link

Why duplicate routes are not allowed? #284

Closed achyut-tokekar closed 3 months ago

achyut-tokekar commented 3 months ago

I was implementing hyper-express in nestjs and got stuck in an issue where if I was importing pino-logger, I'm getting Error: HyperExpress: Failed to create route as duplicate routes are not allowed. Ensure that you do not have any routers or routes that try to handle requests with the same pattern.

After digging further got to know that pino might be internally doing something which is causing all routes to get registered twice, so wanted to know why this restriction is added and how to resolve it?

kartikk221 commented 3 months ago

Duplicate routes are usually a sign of incorrect or buggy behavior as the user is free to route the request to any upstream functions or logic from the sole route handler.

If you would like to disable this behavior, you can fork and remove the following snippet: https://github.com/kartikk221/hyper-express/blob/master/src/components/Server.js#L370-L375

achyut-tokekar commented 3 months ago

@kartikk221 If while creating server we could pass an option to allow duplicate routes?