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

Misleading module + docs, key feature lacking #1382

Open
desmap opened this issue Sep 15, 2019 · 1 comment
Open

Misleading module + docs, key feature lacking #1382

desmap opened this issue Sep 15, 2019 · 1 comment

Comments

@desmap
Copy link

desmap commented Sep 15, 2019

No offense, and maybe I got something wrong but my understanding of a proxy such as nginx is that you can target multiple apps via multiple hostnames/domains, e.g. example1.com and example2.com have both the same A record and a proxy is sending traffic to the right apps and handling diff. ssl certs, etc..

Unsure if this is possible with node-http-proxy.

Everything else which is described in the docs seems to be easily done with plain node and/or standard node-web/http-libs which are used anyway.

@zacanger
Copy link

zacanger commented Apr 21, 2020

You can do that with this library, I'm using it for an API gateway that allows for host header based routing for backwards compatibility. Minimal example:

const proxies = {}

const host1Proxy = httpProxy.createProxyServer({
/* your config here, including certs if need be */
})

proxies.host1 = host1Proxy

const handler = (req, res) => {
  const host = req.headers.host
  if (proxies[host]) {
    proxies[host].web(req, res, {
      /* options here */
    })
    return
  }

  handle404Case(req, res)
}

http.createServer(handler).listen(port)

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

2 participants