Rob--W / cors-anywhere

CORS Anywhere is a NodeJS reverse proxy which adds CORS headers to the proxied request.
MIT License
8.69k stars 6.13k forks source link

Incorrect proxyBaseUrl in case of non root application #80

Open lerminou opened 7 years ago

lerminou commented 7 years ago

I have on my server an Apache application, and I use this nodeJs plugin only to redirect a part of it.

Only the trafic sent to "http://example.com/proxy/[..]" will be routed to the nodeJs application.

To perform this, i create a proxy rule in my apache virtualHost. <Location /proxy> ProxyPass http://127.0.0.1:8081 ProxyPassReverse http://127.0.0.1:8081

The variable proxyBaseUrl is set to the host, but in my case, the base is "http://example.com/proxy/" https://github.com/Rob--W/cors-anywhere/blob/143eff177c7e7d4bf241b83c57dd1e2c6378d53b/lib/cors-anywhere.js#L353 So when the remote server sent a redirection, the next call will not have the "/proxy/" path and will not be redirected to the cors plugin. Is it possible to set this baseUrl as an option ?

It works when I made the modification directly to this line.

Rob--W commented 7 years ago

I think that a proxyBasePath option that defaults to / would make sense. Then the "/" should be removed here: https://github.com/Rob--W/cors-anywhere/blob/143eff177c7e7d4bf241b83c57dd1e2c6378d53b/lib/cors-anywhere.js#L191

Do you want to submit a PR?