且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

即使使用代理,Node.js也不会为React CRA应用程序设置cookie

更新时间:2023-11-14 18:29:58

要允许浏览器设置cookie并遵守Same Origin Policy,您的客户端代码应查询 http://localhost:3000/api/users/login (与客户端相同的主机),而不是(代理的)服务器网址(端口4001).

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).

您还可以将基本网址指定为 $ {window.location.origin}/api 或仅/api .

You can also specify the base url as ${window.location.origin}/api or just /api.