-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow more than route to be registered for the same url and method #31
Conversation
3059945
to
2d922a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This likely require a readme change.
Yep, will change, but are you ok with the breaking change / new approach? I will update the readme and add a changelog entry if so. |
I think your points are good. Personally, I think that it would be annoying for users that do not use constraints to write:
|
Another option is to use an array only if there are multiple constraints, plus an option to always have arrays. |
I think it's kinda weird that someone who's using constraints would have to realize and know that they needed to pass that option, and also, it means that we have to maintain two codepaths instead of one. Personally, I feel that increases overall complexity without really adding much value, because I don't feel Also, for options like |
I'm happy with the change as it is. @Eomm wdyt? |
2d922a0
to
15cf37a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree with @airhorns that a mixed situation would be really annoying.
From my point of view, I think the fastify.routes['/foo'][0]
is annoying because I must be aware of the output (and understand why it is an array) and then acts due to the constraint
feature that a developer could not use.
I see this extra effort.
I think this feature is fine, but I think I may open an issue to add the keepPlain
flag since it would be just a setting for those that would like the plain object 👍🏽
15cf37a
to
7e5d754
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
could you ship a major as well?
just a note in case it comes up for others, this ended up landing as a semver minor in |
Newer fastify versions support route constraints, which means that a path & method don't uniquely identify a route anymore. Fastify will allow multiple route handlers to be added for the same path and method if they have different constraints.
For this reason, I think we should change the data structure exposed by this library to expose these routes. Before this change, this library will only report the most recently registered routes and completely omit previously registered ones.
Instead of
this PR switches us to use an array of route options for each URL:
I think this is still useful in that you can get to the routes you want quickly, but supports reporting all the routes registered and is a bit more future proof.
Also important is that there are new route options that this library omits. I think it'd be more useful to report all the route options like
constraints
(which is built into fastify) orwebsocket
(fromfastify-websocket
). For this reason, I think we should capture the whole route options object fastify sends to theonRoute
hook. That way, downstream consumers of the route map have access to the most information possible.And finally, I think that using the raw
routeOptions
object from fastify allows subsequentonRoute
hooks to modify the route options. Before this change, if this plugin was registered first and then aonRoute
hook was registered after, changes that second hook made to the route options wouldn't be captured. Using the raw object without copying allows this plugin to reflect changes made by subsequent hooks.This is for sure a breaking change, so if y'all are ok with this direction I will add a changelog entry to explain how to upgrade.
Checklist
npm run test
andnpm run benchmark
and the Code of conduct