No documented way to dynamically route to host and rewrite uri #449

Open
robertjchristian opened this Issue Aug 6, 2013 · 5 comments

5 participants

@robertjchristian

Use case:

URL looks like: host:port/a/b/c

Want to map "a" to a host, ie host2:port2, and rewrite to host2:port2/b/c.

There doesn't seem to be a mechanism in place to do such a thing.

Thanks.

@MrSwitch

+1

@Rush

It requires adding a middleware for this that would do such redirects. I have added such feature to https://github.com/RushPL/rush-http-proxy (which is based on node-http-proxy). You may see how it is implemented there (in case you use http-proxy as a module) or otherwise just use my CLI tool.

@robertjchristian

I determined this is actually brain-dead simple, and perhaps why it's not a specific request.

Consider:

// proxy requests to target
proxy.proxyRequest(req, res, TARGET_SERVER);

To rewrite the URL prior to proxy, simple do:

req.url = "/foo";

Of course you can add any logic necessary to the rewrite. Didn't realize it was that simple.

I no longer think there is a need for this as a middleware or a "feature"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment