hapijs / hapi

The Simple, Secure Framework Developers Trust
https://hapi.dev
Other
14.63k stars 1.34k forks source link

Is it possible to dynamically change a path for a route at runtime #1983

Closed briandela closed 10 years ago

briandela commented 10 years ago

Prior to 6.9.0 we were using the private _parsePath method to dynamically modify a route based on some information in the database.

Essentially, we have a route with a path like this: /offers. At application startup/runtime, a check of the database would determine if we need to have this path changed to something like /{market}/offers.

We were doing this in a plugin by determining which routes needed to have the path changes, then changing the route.settings.path value and calling route._parsePath().

Is behaviour like this still possible in 6.9.0?

hueniverse commented 10 years ago

This is a terrible idea. Why not just wait until you have your information and then add the proper routes?

briandela commented 10 years ago

That could work. The design is to have a route like /offers. If the db said to prepend it with /{market}/ to make it /{market}/offers then there should be two routes, with /offers changing to redirect to /{market}/offers.

Makes sense to dynamically add the other routes later and then change the behaviour of the initial ones.

jamesgibson14 commented 6 years ago

It is not a terrible idea, dynamic evaluation at runtime is a very powerful tool. Just as in every design, there are trade offs.

lock[bot] commented 4 years ago

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.