Open iki opened 5 years ago
Hi, thanks for the report. Yes, CORS headers should be added in this case - I will look into it.
I'm not 100% clear what the issue is here.
Your browser made a request to /api/x
- as far as your browser knows this is a regular, local request just like any other. Your browser does not know that the request was proxied to a remote target behind the scenes, therefore your browser would not expect to see CORS headers (e.g. Access-Control-Allow-Origin
) in the response. If a CORS header appeared in the response to a local request, this would be unexpected.
What exactly do you expect to see in the reponse to /api/x
? How does this issue break your app?
@75b I was trying if ws
can add CORS headers to the proxied api server inside a locel docker:
ws -p 8000 --rewrite "/(.*) -> http://localhost:7000/$1" --cors.credentials -v
Providing CORS headers for proxied requests would be a useful feature. Especially because you get the CORS implementation right on contrary to most CORS proxies on docker hub that use an origin wildcard *
, which can't be used with credentials. Nginx can be used, but it's more complex.
Sorry, I haven't had time to action this yet so I will give you instructions on how to test a solution yourself.
Launch ws
with your local middleware plugin in the stack. In this example, I have provided the path to my local fork. I have also included stack
and index
for static files and directory listings. You can use any plugin from the ws --default-stack
list in your stack (the lws-
prefix is optional).
$ ws --stack /Users/lloyd/Documents/lwsjs/rewrite static index
When you have fixed the remote request headers, please let me know how you fixed it. Speak soon!
@iki did you resolve this in the end?
@75lb I used the nginx solution in meantime, but I can test your solution later this week and send a PR
Currently the preflight request is served with correct CORS headers for given origin, but the proxied request response is passed without them.
Would it be possible to use the CORS middleware on proxied requests too?