I need to implement a bunch of routes that do very custom / complex operations on a FeathersJS app.
One of those routes is /Category/disableExclusiveContentsOf/:id
. It runs a query against half a dozen database tables to find rows that relate to the category :id
exclusively. I absolutely cannot do that using the querying abstractions FeathersJS provides. Then, it uses FeathersJS' "local" API to update the rows I found, so that data update events are fired to clients.
However, if I implement the route using Express alone, Feathers authentication / authorization hooks won't run, so the endpoint won't be protected, which is a requirement.
How can I accommodate such things in a FeathersJS application?
You can still implement the route using your own service and use the :id
as route parameter:
app.use('/Category/disableExclusiveContentsOf/:id', {
find() {
// do complex stuff here
}
});
One thing I'd recommend changing is that the URL seems to be action and not resource oriented. This means that someone can change your application data with a GET request which is generally considered not a good practise (e.g. in some cases the Google crawler came in and deleted/changed a bunch of things).
Feathers encourages you to think in resources rather than custom routes and actions. In your case you would have an ExclusiveContents
service that you can POST
to:
app.use('/Category/ExclusiveContents/:categoryId', {
create(data, params) {
// do complex stuff here
params.categoryId // the id of the category
data // -> additional data from the POST request
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With