admin管理员组文章数量:1400559
Is it possible to disable the CORS checking functionality in the jsdom
node module?
The CORS errors are particularly difficult to debug in my use case (clientside testing) and do not occur in the actual environment I am running the program.
Perhaps some environmental variable we can set when initializing the object? e.g.,
window = new jsdom.JSDOM(``,{
cors : false,
}).window;
Is it possible to disable the CORS checking functionality in the jsdom
node module?
The CORS errors are particularly difficult to debug in my use case (clientside testing) and do not occur in the actual environment I am running the program.
Perhaps some environmental variable we can set when initializing the object? e.g.,
window = new jsdom.JSDOM(``,{
cors : false,
}).window;
Share
Improve this question
edited Mar 23, 2018 at 15:43
Vadim Kotov
8,2848 gold badges50 silver badges63 bronze badges
asked Mar 23, 2018 at 15:40
Ulad KasachUlad Kasach
12.9k13 gold badges69 silver badges90 bronze badges
8
- what does jsdom have to do with cors/ajax? doesn't it just mimick the DOM? – Kevin B Commented Mar 23, 2018 at 15:45
- @KevinB jsdom implements XMLHttpRequest and other API's found in the browser. – Ulad Kasach Commented Mar 23, 2018 at 15:47
- Right, but why would that be throwing CORS errors? – Kevin B Commented Mar 23, 2018 at 15:48
- @KevinB It allows a url parameter to be passed as an option for which it then considers same-origin restrictions – Ulad Kasach Commented Mar 23, 2018 at 15:50
- 1 It's more about the server not allowing you to request from a client that is not on the same origin. This issue seems to confirm that's it's not possible in JSDOM. – Pierre C. Commented Mar 23, 2018 at 15:54
3 Answers
Reset to default 6As stated in this issue on JSDOM Github repository, JSDOM acts like a browser and the same-origin policy applies.
It cannot be disabled from there.
The solution would be to add headers to the resource server allowing the origin of the client which makes the request.
Just set testURL
in your jest.config.js to your API address.
Set window._origin
to the requested origin such as http://www.example.
. Works for Jest 27.5.1.
本文标签: javascriptdisable CORS checking in jsdom on nodejsStack Overflow
版权声明:本文标题:javascript - disable CORS checking in jsdom on nodejs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744165086a2593514.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论