You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First off, let me say that I'm an Express beginner and so far I'm very impressed with what it can do.
I set up my node.js application to watch file changes and those file changes actually can incur the need to alter routes. Therefore I searched the routing documentation and it seems there is no official, documented way to do it.
I quickly searched if this issue already existed on GitHub but I couldn't find it via "remove" or "remove routes".
However those don't seem to be well documented and I don't see why Express shouldn't have an officially documented function à la "app.remove()" or a similar mechanism to remove routes.
If there is something I missed please let me know.
The text was updated successfully, but these errors were encountered:
Correct, there is no official way because we cannot optimize things if the stack can be mutable at runtime. The way we recommend you do it is to simply swap a router at runtime:
varexpress=require('express')varapp=express()varrouter=undefined// this should be the only thing on your appapp.use(function(req,res,next){// this needs to be a function to hook on whatever the current router isrouter(req,res,next)})functiondefineStuff(){router=express.Router()// define everything on _router_, not _app_router.get('/', ...)}// now do you watch and when something changes// call defineStuff()
Correct :) Because Node.js is async, when you start to alter the routes, there are likely various requests in various states within the stack. Requests may re-enter the stack, and since this is done by index, removing a route will cause strange behavior for in-flight requests. It's the same reason we limit to only adding new routes at the end of the stack :)
I'm here if you still have questions, so feel free to reply back here if you need :) As for quick, it's really timing as I just happen to be on mucking with all the Express repos right now :D
First off, let me say that I'm an Express beginner and so far I'm very impressed with what it can do.
I set up my node.js application to watch file changes and those file changes actually can incur the need to alter routes. Therefore I searched the routing documentation and it seems there is no official, documented way to do it.
I quickly searched if this issue already existed on GitHub but I couldn't find it via "remove" or "remove routes".
A few minutes of Google-fu later it seems there are some ways to do it:
http://stackoverflow.com/questions/15027514/node-js-remove-route-while-server-is-running
http://stackoverflow.com/questions/10378690/remove-route-mappings-in-nodejs-express
However those don't seem to be well documented and I don't see why Express shouldn't have an officially documented function à la "app.remove()" or a similar mechanism to remove routes.
If there is something I missed please let me know.
The text was updated successfully, but these errors were encountered: