-
Notifications
You must be signed in to change notification settings - Fork 21
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
Rewrite of "location" header #59
Comments
@planetrenner-martin Can you just specify a use case? |
Hi, we have a client in Javascript, which calls a REST API on a backend server. connect-modrewrite acts as a proxy to this backend server. During authentication, the backend server answers with a "HTTP redirect" ("location" header in the HTTP response). Because modrewrite is not acting as a reverse proxy, the client suddenly sees the IP address of the backend server in the "location" header. This breaks the authentication process, because now the client tries to communicate directly with the backend server (and thus bypassing modrewrite). |
OK I see seems legit. I will try to look into it in the near future. |
I had the same problem here. Header edit* Location http://${page_address}/(.*) http://${proxy_address}/$1 |
@rbperegrino @planetrenner-martin any suggestion of how the API should look like? |
Hi, good question. I am only an ordinary user and have no in-depth knowledge. The reverse proxy makes only sense for request patterns with the "proxy" [P] flag set. But to keep the API clean, I would introduce a second and optional list of tuples, like modRewrite([
'^/test(.*)$ http://backend.example.org/$1 [P]'
], [
'/test http://backend.example.org/'
]) (I would use the same syntax as the Apache directive ProxyPassReverse). In this example, if a request was made to |
I think it is probably easier with: modRewrite([
'^/test/(.*)$ http://backend.example.org/$1 [PR]'
]) And let modrewrite magically figure out how it should rewrite the location header. |
No no no Actually, in apache, it discourages you to even use Do you want to reverse proxy, and still rewrite rules? Do it with a proxy! Here is how to configure a reverse proxy with connect-modrewrite and proxy-middleware var connect = require('connect');
var modRewrite = require('connect-modrewrite');
var proxy = require('proxy-middleware');
var url = require('url');
var app = connect()
.use(modRewrite([
"^\/api\/(.*) /send-to-api/api/$1 [L]",
"^(.*)\/css\/(.*) /send-to-ui/css/$2 [L]",
"^(.*)\/js\/(.*) /send-to-ui/js/$2 [L]",
"^(.*)\/images\/(.*) /send-to-ui/images/$2 [L]",
"^(.*)\/fonts\/(.*) /send-to-ui/fonts/$2 [L]",
"^(.*) /send-to-ui/index.html [L]"
]))
.use('/send-to-api', proxy(url.parse('http://api.server.dev/'))) // Don't forget the last backslash
.use('/send-to-ui', proxy(url.parse('http://ui.server.dev/' ))) // Don't forget the last backslash
.listen(9000) Check that I use In this case, only the And yes, in case of redirects, |
Hi,
it would be great if this module could rewrite the "location" header of a http response. I think that the matching Apache httpd option would be "ProxyPassReverse".
Regards,
Martin
The text was updated successfully, but these errors were encountered: