Nodejs won't set cookie for React CRA application even with proxy
To allow the browser to set cookies and adhere to Same Origin Policy, your client code should query http://localhost:3000/api/users/login
(same host as client) instead of the (proxied) server url (port 4001).
You can also specify the base url as ${window.location.origin}/api
or just /api
.
According to what riwu mentioned cookie domain should match, in my case setting "cookieDomainRewrite": "localhost",
works
Below complete config for setupProxy.js
in React:
const {createProxyMiddleware} = require('http-proxy-middleware');module.exports = function (app) { app.use( '/api', createProxyMiddleware({ target: 'http://localhost:8000', changeOrigin: true, cookieDomainRewrite: "localhost", }) );};