Is it possible to add a cookie on a different domain request with nginx?

1.8k views Asked by At

So this is my context:

I have a frontend local app on port 4203. A nginx server on port 3000 would point all requests at '/' to localhost:4203 all requests to localhost:3000/api are proxied to https://example.com/api which would also set a cookie on my browser. After acquiring the cookie, every request to a relative path like /api/resource work fine with the cookie included in the header. The problem is that I have some absolute links on my frontend app which I would like not having to parse them. So I'll have requests to https://example.com/api/anotherResource on which I can't apply the cookie for some reason so they are failing.

Is it even possible to add the cookies on this absolute path requests ?

Or maybe a way to proxy requests at https:/example.com/api/anotherResource to first acquire the cookie on localhost.

here is my nginx config:

server {
  listen       3000;
  server_name  localhost;

  location ^ ~ /api/ {
    proxy_pass    https://example.com/api;
    }
  location / {
    proxy_pass    http://localhost:4203;
  }
}
0

There are 0 answers