Search code examples
node.jsnode-http-proxy

wildcards in node-http-proxy router table


can somebody tell me how to use wildcards in the router table of node-http-proxy?

for example for wildcard subdomains, something like *.domain.de
i know there are RegEx used but i cant get it to work.
i tried like

'([a-zA-Z0-9_]).domain.de': '127.0.0.1:8085',

and

 '([^.]*).domain.de' : '127.0.0.1:8085'

but none seem to redirect.


Solution

  • I've not done this myself but I would think that the whole string needs to be a regular expression. So it would be something like:

    '[a-zA-Z0-9_]\.domain\.de': '127.0.0.1:8085',
    

    Note the escaping of the dots. In fact, this would be simpler (though perhaps not as secure) if that format is correct:

    '.*\.domain\.de': '127.0.0.1:8085',
    

    Or even:

    '\w*\.domain\.de': '127.0.0.1:8085',
    

    Sadly, and as usual with all things Node, you are expected to "know" this stuff - mainly by reading the source code :( This is one of the key issues that puts me off using Node in the real world.