expressjs/express

Unmounting middleware

jmelis opened this issue · 1 comments

Mounting a middleware function is documented here: https://expressjs.com/en/5x/api.html#app.use

I have a use case to unmount a middleware function: I'm exposing an express server with a dynamic collection of ApolloServers. Once the data has expired, I want to unmount it.

The current way I'm accomplishing this is by splicing app._router.stack. This feels like an unsupported method which may break in any future express version.

What is the recommended approach here? Could we request a supported way to unmount a middleware function?

There is no safe way to unmount a middleware since it will corrupted concurrent requests routing through the system. The method is really just to swap out one router for another router. If you can provide more details on exactly what you are trying to do, we can help you with a solution.