我有一个带有Jest + MSW的reproduction repo,我正在尝试让MSW接收跨域cookie。默认情况下,JSDOM加载在http://localhost上。当向该域发送获取请求时,MSW也会在该域上侦听,一切正常,收到cookie。
但是,当尝试向另一个域发送请求时,不会向http://localhost:4444发送任何cookie。奇怪的是,如果我注释掉MSW并在同一端口上启动一个express服务器,它确实会接收所有cookie。为什么他们会被送到快递服务器而不是MSW?
最后,同样奇怪的是,如果MSW和express服务器都在运行,MSW在4444上,Express在5555上,express服务器将不再接收cookie。这就好像MSW的beforeAll(() => server.listen());正在以某种方式杀死跨域cookie。
Cookie集:
setCookie("local00=L00", "http://localhost");
setCookie("local44=L44", "http://localhost:4444");
setCookie("local55=L55", "http://localhost:5555");
setCookie("local66=L66", "http://localhost:6666");fetch(http://localhost) --> handler("http://localhost"): OK! all cookies received
fetch(http://localhost:4444) --> handler("http://localhost:4444): No cookies received
OR
--> express("http://localhost:4444): OK! all cookies received
fetch(http://localhost:4444) --> handler("http://localhost:5555): No cookies received
AND
--> express("http://localhost:4444): No cookies received如何向MSW发送跨域请求,并让MSW接收cookie?
发布于 2021-11-07 00:55:31
当在JSDOM中运行时,MSW目前不支持window.fetch上的credentials选项(参见related issue和pull request that adds that support)。期待在下一个次要版本中添加此功能。谢谢。
https://stackoverflow.com/questions/69743031
复制相似问题