Http-proxy-middleware: How to setup multiple proxies?

Created on 14 Jul 2016  路  2Comments  路  Source: chimurai/http-proxy-middleware

So we have a working proxy that redirects local api requests to our dev public api:

server.middleware = proxyMiddleware('http://localhost:3000/platform/api/v2', {
        target: 'https://public-api.domain.com',
        headers: { host: 'public-api.domain.com' },
        pathRewrite: {
            '^/platform/api/v2': '/api/v2'
        }
    });

However we now need another proxy for one specific api call that needs to goto another api server (ie: https://public-api.domain2.com). I'v searched around and tried different ideas, but nothing seems to work. How can this be done?

question

Most helpful comment

Can think of 2 ways to do it.

# 1
Create 2 seperate proxies; Use context-matching to include or exclude certain paths.

You can use glob patterns or a custom function in context matching.

server.middleware = [proxyMiddleware(/*... config1 ...*/), proxyMiddleware(/*... config2 ...*/)]

# 2
Create a single proxy and use the router option to route a specific request to a different target

All 2 comments

Can think of 2 ways to do it.

# 1
Create 2 seperate proxies; Use context-matching to include or exclude certain paths.

You can use glob patterns or a custom function in context matching.

server.middleware = [proxyMiddleware(/*... config1 ...*/), proxyMiddleware(/*... config2 ...*/)]

# 2
Create a single proxy and use the router option to route a specific request to a different target

No response... closing issue.
Feel free to re-open.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jack-Works picture Jack-Works  路  8Comments

dzz9143 picture dzz9143  路  3Comments

nikksan picture nikksan  路  3Comments

gajus picture gajus  路  8Comments

DylanPiercey picture DylanPiercey  路  6Comments