I have tried looking at past responses to this type of issues, such as the following, but they all throw various errors:
- http-proxy-middleware, how to copy all/cookie headers
- https://github.com/chimurai/http-proxy-middleware/issues/78
- http-proxy-middleware, how to copy all/cookie headers
My proxy setup returns the correct Response Headers
with cookies to be set: set-cookie: JSESSIONID=yElsHUaPE8Ip_AAD_oIfTQ; Path=/; Secure; HttpOnly;
. These are not session cookies.
However, my login is officially unsuccessful because the JSESSIONID
does not get stored as a cookie.
Here is my proxy setup:
const proxyTable = {
"/url": "http://localhost:4040/url",
"proxy.url.com/": "http://localhost:4040/",
};
const signin_proxy_options = {
target: host,
autoRewrite: true,
secure: true,
reqBodyEncoding: null,
changeOrigin: true,
logLevel: "debug",
router: proxyTable,
protocolRewrite: "http",
cookieDomainRewrite: { "*": "" },
onProxyRes: function(proxyRes, req, res) {
if (proxyRes.headers["set-cookie"] !== undefined) {
console.log("** SET-COOKIE: ", proxyRes.headers["set-cookie"]);
const cookieJar = proxyRes.headers["set-cookie"];
// cookieJar = 'JSESSIONID=yElsHUaPE8Ip_AAD_oIfTQ; Path=/; Secure; HttpOnly;'
var temp = cookieJar.split(";")[0].split("=");
// temp = [ 'JSESSIONID', 'yElsHUaPE8Ip_AAD_oIfTQ' ]
res.cookie(temp[0], temp[1]);
}
},
};
// Proxy configuration
const signin_proxy = proxy(signin_filter, signin_proxy_options);
app.use("/signin", signin_proxy);
On success, the server returns a 302
to redirect. Could this have an impact?? That is why I have the proxyTable in place...
Also, since it looks like the response is OK, I have removed the onProxyRes
field hoping that would set it automatically, but no luck either.
I appreciate any ideas/solutions.