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

robertjchristian opened this Issue Aug 6, 2013 · 5 comments

5 participants


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.





It requires adding a middleware for this that would do such redirects. I have added such feature to (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.


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


// 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