I'm using http-proxy-middleware@2.0.6 to proxy requests to an endpoint where a website is hosted. Before this proxy happens, my application sets a few cookies (using the regular res.cookie() method). The proxied endpoint (the website application), also sets some response cookies.
For eg.
Cookie set by my node app: res.cookie('node_cookie', 'node')
Cookie set by the proxied website: 'web_cookie': 'web' (somewhere in the website's JS)
The issue I'm facing is that the cookies which my node app is trying to set are never reflected in the browser. Only the cookies coming in the proxied website's response are set.
Now after digging a bit, we've got these two objects, proxyRes and res:
onProxyRes: (proxyRes, req, res) => {
console.log(res.getHeaders()['set-cookie']); // Has 'node_cookie'
console.log(proxyRes.headers['set-cookie']); // Has 'web_cookie'
}
Only the cookies present in proxyRes are being set, and the cookies from the current res object are ignored for some reason.
Additionally, I noticed that the res cookies are getting set successfully when proxyRes has no Set-Cookie header.
Step-by-step reproduction instructions
1. Set some cookies in Node/Express response using res.cookie(...)
2. Try proxying to an endpoint which sets a cookie
3. Notice on the browser that only the proxied website's cookies are set. The ones being set via Node are ignored.
Expected behavior (be clear and concise)
Both sets of cookies should be set successfully.
How is http-proxy-middleware used in your project?
Checks
http-proxy-middleware
.Describe the bug (be clear and concise)
Hi,
I'm using http-proxy-middleware@2.0.6 to proxy requests to an endpoint where a website is hosted. Before this proxy happens, my application sets a few cookies (using the regular
res.cookie()
method). The proxied endpoint (the website application), also sets some response cookies.For eg. Cookie set by my node app:
res.cookie('node_cookie', 'node')
Cookie set by the proxied website:'web_cookie': 'web'
(somewhere in the website's JS)The issue I'm facing is that the cookies which my node app is trying to set are never reflected in the browser. Only the cookies coming in the proxied website's response are set.
Now after digging a bit, we've got these two objects,
proxyRes
andres
:Only the cookies present in
proxyRes
are being set, and the cookies from the currentres
object are ignored for some reason.Additionally, I noticed that the
res
cookies are getting set successfully whenproxyRes
has no Set-Cookie header.Step-by-step reproduction instructions
Expected behavior (be clear and concise)
Both sets of cookies should be set successfully.
How is http-proxy-middleware used in your project?
What http-proxy-middleware configuration are you using?
What OS/version and node/version are you seeing the problem?
Additional context (optional)
No response