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 for hostname matching #96

Open
fabsrc opened this issue Jan 18, 2018 · 1 comment
Open

Support for hostname matching #96

fabsrc opened this issue Jan 18, 2018 · 1 comment
Labels

Comments

@fabsrc
Copy link

fabsrc commented Jan 18, 2018

When multiple domains point to the gateway it would be nice to be able to use different APIs and/or paths for them. E.g. api.example.com should proxy all incoming requests to http://httpbin.org while docs.example.com should proxy all incoming requests to https://requestb.in/1f1ww8l1.
This should be possible by using a single hostname, a list of hostnames or a wildcard/regex syntax.

For comparison here is the API configuration documentation for express-gateway and kong where this feature is already supported.

The ExpressJS vhost module can be used to implement this feature.

@thiagobustamante
Copy link
Collaborator

Hi,

We can configure this scenario in tree-gateway through a Router middleware.

Proxy Router is a kind of middleware that can be used to change how the request pipeline will handle your requests. You can define your own middleware function or use one of the already included middlewares.

To route something based on the host header, you could configure something like:

---
name: MyAPI
version: 1.0.0
path: "/myapi"
proxy:
  target:
    router:
      middleware:
        name: header
        options:
          name: host
          defaultTarget: http://httpbin.org
          destinations: 
            - target: http://httpbin.org
              value: api.example.com
            - target: https://requestb.in/1f1ww8l1
              value: docs.example.com

In this example, I am using this middleware, included in the default distribution. It is a simple middleware that can not handle expressions like *.example.com (like vhost that you suggested).

I want to say that I really like the suggestion to support expressions like that and I will add this feature to the next release.

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

No branches or pull requests

2 participants