-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
[11.x]platform-fastify: custom methods should be registred #14510
Comments
Instead of checking whether a route handler has a @Body decorator, I'd say we could determine IF a given HTTP method should allow a body or not based on its spec, e.g., SEARCH allows passing a body, so let's just set |
For custom methods, having the choice on the use of a body remains a nice option. For example, COPY/MOVE methods are used in some contexts with and without a body. Allowing the default body for these methods would be more generic and less restrictive (and that was the case until now.) |
@johaven you won't be able to determine whether a method is annotated or not in this context (the adapter receives a wrapped proxy callback with no metadata attached) |
@kamilmysliwiec This is what I noticed when trying to retrieve the ROUTE_ARGS_METADATA :( Are you ok with my suggestion to set hasBody to true for these methods by default? |
Sounds good! |
There is another problem, this one concerns the decorator @ALL Example: @All(WDAV_PATH)
async files(@Req() req: FastifyDAVRequest, @Res({ passthrough: true }) res: FastifyReply) {
switch (req.method) {
case HTTP_METHOD.PROPFIND:
return this.webdavMethods.propfind(req, res, SPACE_REPOSITORY.FILES)
....
case HTTP_METHOD.COPY:
case HTTP_METHOD.MOVE:
return this.webdavMethods.copyMove(req, res)
default:
return res.status(HttpStatus.METHOD_NOT_ALLOWED).send()
}
} @kamilmysliwiec If the @ALL decorator is to literally allow access to all methods, shouldn't we declare all non-standard methods on the fastify instance during initialization? |
I'm not sure if anyone willing to use MOVE or COPY would do so through the ALL decorator. We can update the docs and clarify that ALL registers routes for all "original" methods (those that are available on the adapter out-of-the-box) and not for custom methods. |
Let's track this here #14511 |
Did you read the migration guide?
Is there an existing issue that is already proposing this?
Potential Commit/PR that introduced the regression
No response
NestJS version
11.x
Describe the regression
This is a regression following the upgrade to version 5 of fastify, the SEARCH method and the new methods implemented need to be registered during the route injection phase (https://fastify.dev/docs/v5.1.x/Guides/Migration-Guide-V5/#removal-of-some-non-standard-http-methods)
instance.route(routeToInjectWithOptions) returns the following error:
Minimum reproduction code
No response
Input code
No response
Expected behavior
Custom methods should be registered automatically.
Other
I wanted to do a PR, the fix is pretty simple, just check if the method is supported, in the injectRouteOptions function:
But I'm stuck on how to determine if the handler has a @Body decorator to use the hasBody option during the injection:
The other problem is to handle the case of multiple routes that may or may not have a body for the same custom method.
The text was updated successfully, but these errors were encountered: