Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using wildcards or regex in router tables? #355

Closed
trusktr opened this issue Dec 28, 2012 · 4 comments
Closed

Using wildcards or regex in router tables? #355

trusktr opened this issue Dec 28, 2012 · 4 comments

Comments

@trusktr
Copy link

trusktr commented Dec 28, 2012

Hi, if I do the following, then www.foobar.com doesn't work:

var httpProxy = require('http-proxy'),
    apache = '127.0.0.1:5678',
    node = '127.0.0.1:1234';

var options = {
    hostnameOnly: true, // host name proxies, for now.
    router: {
        'foobar.com'                        :node,
        'barfoo.com'                    :apache
    }
}

var proxyServer = httpProxy.createServer(options);
proxyServer.listen(80);
console.log('Proxy server started on port 80.');

To make www.foobar.com work I have to add it manually:

var httpProxy = require('http-proxy'),
    apache = '127.0.0.1:5678',
    node = '127.0.0.1:1234';

var options = {
    hostnameOnly: true, // host name proxies, for now.
    router: {
        'foobar.com'                        :node,
        'www.foobar.com'                    :node,
        'barfoo.com'                        :apache
        'www.barfoo.com'                    :apache
    }
}

var proxyServer = httpProxy.createServer(options);
proxyServer.listen(80);
console.log('Proxy server started on port 80.');

I would also have to add any other subdomains manually. How can I avoid doing that so that for example all requests to barfoo.com go to apache regardless of the subdomain? If those were regex, then foobar.com would match anything.foobar.com but that's not the case.

@trusktr
Copy link
Author

trusktr commented Dec 28, 2012

Wait, nevermind, I forgot to remove the hostnameOnly: true option. Doh.

@trusktr trusktr closed this as completed Dec 28, 2012
@trusktr
Copy link
Author

trusktr commented Dec 28, 2012

Wait, nevermind. I'm still having some trouble. So If I have

var httpProxy = require('http-proxy'),
    apache = '127.0.0.1:5678',
    node = '127.0.0.1:1234';

var options = {
    router: {
        'foobar.com'                        :node,
        'barfoo.com'                   :apache
    }
}

var proxyServer = httpProxy.createServer(options);
proxyServer.listen(80);
console.log('Proxy server started on port 80.');

and I try to visit www.barfoo.com, it works. If I try to visit one.two.three.foobar.com, it still doesn't work unless I do something like the following.

var httpProxy = require('http-proxy'),
    apache = '127.0.0.1:5678',
    node = '127.0.0.1:1234';

var options = {
    router: {
        'foobar.com'                        :node,
        'one.two.three.foobar.com'          :node,
        'barfoo.com'                   :apache
    }
}

var proxyServer = httpProxy.createServer(options);
proxyServer.listen(80);
console.log('Proxy server started on port 80.');

Can we prevent having to add the extra line for one.two.three.foobar.com?

@trusktr trusktr reopened this Dec 28, 2012
@breck7
Copy link

breck7 commented Jan 26, 2013

I also had this issue. I think the general solution would be to allow a callback function for when there is no match in the router table. We are using such a solution in production. Pull request:

#333

@trusktr
Copy link
Author

trusktr commented Jan 31, 2013

@breck7 That's a good idea. I think changing the router functionality so that regex can be used would be very nice. Or maybe something like Google Chrome's settings where you can add domain exceptions to various settings like [*.]foobar.com which matches anything.foobar.com or whatever.foobar.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants