By default, the cookies express-session sets will not work if your server's url isn't the same origin as your front end page where you are making requests from. For example, if you are using Create React App's server on localhost:3000
, and your server is running at localhost:8000
, cookies won't be saved without extra configuration for CORS.
If you can avoid multiple origins, I recommend doing that. A single origin avoids CORS configuration which tends to be troublesome. Most front end build tools (including Create React App) have options to proxy requests to your backend server. Even better are tools which build your front end to files that can be directly served by your backend (such as using Parcel's watch
command).
The CORS configuration will include:
- Setting
SameSite
on your cookie options tonone
.