-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Set plugin prefix in the plugin itself #2667
Comments
Not sure if it's exactly what you're looking for but you could append to the prefix inside the register function? index.js
plugin.js
The route is then |
Yeah that is want to avoid. I want to give the plugin the responsibility of setting its own prefix like I have a |
The plugin does have the responsibility in my example though. It's modifying the prefix internally. Are you just looking for a way to do the same in config instead? |
oh wow totally missed that line 😮 and yeah that works but config would look cleaner and it will be 1 line of code from the looks of it then |
I am not a fan of messing with the realm config this way. Config should be treated as read-only (and will probably become const at some point). The right way to accomplish this is with a utility that simply adds a prefix before calls to |
Is there a way to come between the route calls? Because then I could make an easy plugin |
You can decorate the server with your own version of adding a route function. |
That's a good solution to a problem closely related to a question/proposition I posed over at #2566. |
@hueniverse like overriding the function or decorating with server.decorate/method(don't know the right one from the top of my head) |
Ugh, sorry @AdriVanHoudt – I linked to the wrong issue. Try #2650. I assume that he meant to decorate |
I am not fully following your explanation in the issue and yeah something like Var oldRoute = server. Route()
Server.route = function () {
My stuff
} (Programming on phone :P) |
See docs for Ex. var specialRoute = function (definition) {
// Transform or glean info from definition then...
server.route(definition);
}
server.decorate('server', 'specialRoute', specialRoute);
server.specialRoute({/* Route definition */}); |
@AdriVanHoudt You could have a plugin that does this:
And then use it like this:
Each route is then prefixed with |
can I do |
No, you'll get an error:
|
😞 var old = server.route;
server.route = function() {
// my own stuff...
old();
}; |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Atm you can pass a plugin prefix with the
options
onserver.register
. I would like to define a 'global' (at plugin level) prefix as well so the plugin also has control over the prefix.I would still allow the prefix to be passed by the
options
.This would result into
route = options.prefix + plugin.attributes.prefix + route.path
Would you accept a PR for this?
The text was updated successfully, but these errors were encountered: