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

Support path-based routing #331

Open
kamal opened this issue Jan 31, 2019 · 2 comments
Open

Support path-based routing #331

kamal opened this issue Jan 31, 2019 · 2 comments

Comments

@kamal
Copy link

kamal commented Jan 31, 2019

I have a top-level domain that fronts several services. For example:

  • api.example.com/a/billing/* will route to billing.example.internal/*
  • api.example.com/a/users/* will route to users.example.internal/*

Currently, the rewrite above is handled by Cloudflare. I'd like to emulate this setup in Hotel so that my local environment is similar to production. Is there somewhere in Hotel where I can perform the rewrite? My other option is to stand up a standalone rewriting proxy that sits on api.example.localhost and routes it to the other hosts.

@bbtx0
Copy link

bbtx0 commented Jun 4, 2019

@kamal Did you find a solution for this scenario? I am interested as well

@kamal
Copy link
Author

kamal commented Jun 8, 2019

@GabrieleDS I ended up writing a proxy with node-http-proxy and running it with hotel alongside the other apps. The proxy itself looks something like this:

const rules = [
  {
    prefix: "/a/billing",
    host: "billing.envoy.dev"
  },
  {
    prefix: "/a/users",
    host: "users.envoy.dev"
  }
];

proxy.on("proxyReq", (proxyReq, req, res, options) => {
  const fullUrl = `https://app.envoy.dev${req.url}`;

  rules.some(({ prefix, host }) => {
    if (req.url.startsWith(prefix)) {
      logger.info(`Rewriting Host to ${host}: ${req.method} ${fullUrl}`);
      proxyReq.setHeader("Host", host);

      return true;
    }
  });
});

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