expressjs / vhost

virtual domain hosting

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Removing vhosts

jbergstroem opened this issue · comments

Was looking at removing vhosts at runtime the other day. There doesn't seem to be a nice way to identify the hostnames that are added to the routing stack; so messing with router._stack quickly becomes a pain. I was thinking that we could perhaps add an identifier - such as hostname - to the middleware key or similar so it can be identified (and then spliced from router._stack). Thoughts?

Express doesn't even support removing middleware. If it did, this module could hook into whatever mechanism I assume. Splicing private variables sounds like a bad idea I wouldn't want to encourage here.

Gotcha. Thanks for the quick reply.

👍 totally open to adding something if there is a hook in some framework. For example, maybe the framework will look for a string in middleware.id property, then we can certainly populate it with something :)

I tried finding out more info about what the middleware keys does and thought we could chuck it in there. Anyway, guess we need to talk about middleware deletion first; killing routes from routes._stack doesn't necessarily reload them; app.unuse() would be the preferred way.

I tried finding out more info about what the middleware keys does and thought we could chuck it in there.

I'm not familiar with what this is? Can you elaborate?

@dougwilson said:
I'm not familiar with what this is? Can you elaborate?

Dumping the middleware stack for router, I see this:

  Layer {
    handle: [Function: vhost],
    name: 'vhost',
    params: undefined,
    path: undefined,
    keys: [],
    regexp: { /^\/?(?=\/|$)/i fast_slash: true },
    route: undefined },

Couldn't find any clear documentation about this, but it seems to be some kind of metadata; hence my suggestion. Anyway, I'm open to any solution!

Gotcha. I think that is all internal information from Express routing; the middleware doesn't have a way to influence any of those values except name and handle.