-
-
Notifications
You must be signed in to change notification settings - Fork 768
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
After migrating to v5 from v4 the matching service name collides with the rest defined endpoints. #3553
Comments
We are experiencing the same issue. We only just now got around to upgrading to v5. We have roughly 20 routes like this that are now broken. Some of these are used by external API consumers, so we can't easily redefine these, as that would be considered a breaking change. I did some testing and it appears to only be an issue with I tried to investigate a bit, it seems that the route is being detected too eagerly in the It only seems to affect custom Express routes, any normal service registered under the same path gets routed properly. Small reproduction / investigation logs// feathers-chat-ts/src/services/users/users.ts
export const user = (app: Application) => {
console.log('feathers-chat - registering: /users/test')
app.use('/users/test', (req, res) => {
res.json({ message: 'Hello from the user service' })
})
console.log('feathers-chat - registering: /users')
app.use('users', new UserService(getOptions(app)), {
methods: userMethods,
events: []
})
} Output of
It seems like the route is being registered correctly, but the lookup fails. If I remove the
Here the Update - hacky workaroundI found a workaround that works for regular It seems that adding an empty Feathers service object in between causes the route to be registered properly. Then you can define the Express handler as the third argument (which will be an express middleware, but you can just respond here as well): app.use(
'/users/test',
+ {
+ async find() {
+ return {};
+ },
+ },
(req, res) => {
// Express implementation
}
);
app.use('users', new UsersService()); |
Small update: I made a reproduction which illustrates the routing breaking between v4 and v5. I realized that the hacky workaround I posted in my previous comment doesn't actually work all too well, since the hooks from the base service are now always being called as well for the nested endpoint. This breaks some of our endpoints, since they don't contain the expected data/params by the hooks |
Another update: there was an issue with my hacky workaround to pass an empty service, as that causes all requests to that endpoint to first go through all the global I found another workaround that seems to result in the behavior of v4, by making use of the app.use('/users/test', createEmptyPassthroughService(), {
express: {
before: [
(req, res, next) => {
// Optionally do whatever in the first middleware
next()
},
(req, res) => {
res.json({ message: 'Hello from express endpoint /users/test' })
}
]
}
}); |
Description
It is not really an issue, but something I have faced while upgrading from version 4 to version 5.
In version 4 I have a service named
items
, with some custom events:I also had the rest endpoint defined:
So when calling the app with
items/new
endpoint it will go to the defined rest endpoint handler and emit the event.After upgrading to v5, the services file was updated to:
and the rest endpoint definition is the same as before, but the issue now is when calling a post request with
items/new
the service
create
is being called not the rest defined endpoint.Is there a way to explicitly set the priority for the rest defined endpoint?
Just renaming a service is an option but in this case, the relevant clients have to update the service names as well.
The text was updated successfully, but these errors were encountered: