# Disable CORS, need help

**URL:** <https://swi-prolog.discourse.group/t/disable-cors-need-help/3346>\
**Category:** General\
**Created:** [December 5, 2020, 7:03pm UTC](https://swi-prolog.discourse.group/t/disable-cors-need-help/3346 "2020-12-05T19:03:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![roger40](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@roger40](https://swi-prolog.discourse.group/u/roger40)\
**Post date:** [December 5, 2020, 7:03pm UTC](https://swi-prolog.discourse.group/t/disable-cors-need-help/3346/1 "2020-12-05T19:03:24Z")

</div>

Hello, im in a school project and we are developing a website in angular that uses an api in node.js and also uses a swi prolog server to do some algorithms , then the swi prolog uses the api to get information in the database to do the algorithm.  
At this time everything is working fine the only error is when i try to comunicate from the spa to prolog server i get the error :

Access to XMLHttpRequest at ‘[http://localhost:5000/plannings/GeneratorAllSolutions](http://localhost:5000/plannings/GeneratorAllSolutions)’ from origin ‘[http://25.86.119.124:8080](http://25.86.119.124:8080)’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.

I have tried to use the http cors module and set the defualt settings to [\*] then inside the handler i tried :

cors\_enable(Request,  
[methods([get,post,delete])  
]),

still getting same error, if you want i can send you my code.  
any ideas ? thanks

---

<div class="post-metadata">

**Author:** ![roger40](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@roger40](https://swi-prolog.discourse.group/u/roger40)\
**Post date:** [December 5, 2020, 7:36pm UTC](https://swi-prolog.discourse.group/t/disable-cors-need-help/3346/3 "2020-12-05T19:36:13Z")

</div>

thanks gona keep trying

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [December 5, 2020, 8:06pm UTC](https://swi-prolog.discourse.group/t/disable-cors-need-help/3346/4 "2020-12-05T20:06:22Z")

</div>

If you set up your server to serve the files, then there’s no need to worry about CORS.

See [Simple Prolog server with JavaScript client](https://swi-prolog.discourse.group/t/simple-prolog-server-with-javascript-client/2898)

If you have questions about how it’s done, please add a comment to the “Prolog server” discussion or raise an issue on github.

---

<div class="post-metadata">

**Author:** ![drspro](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/drspro/32/3509_2.png) [@drspro](https://swi-prolog.discourse.group/u/drspro)\
**Post date:** [December 7, 2020, 10:59am UTC](https://swi-prolog.discourse.group/t/disable-cors-need-help/3346/5 "2020-12-07T10:59:34Z")

</div>

I have experienced similar messages form the web-browser, what i found out is that If the Swi-server does not give an answer at all, for example an empty answer or an error, that the Browser Always messages this as a CORS error which doesnt strictly has to be the case,

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [December 7, 2020, 5:59pm UTC](https://swi-prolog.discourse.group/t/disable-cors-need-help/3346/6 "2020-12-07T17:59:33Z")

</div>

> [@roger40](#):
>
> XMLHttpRequest

`fetch()` is the modern replacement for `XMLHttpRequest()`. There is an example of using `fetch` in [my client code](https://github.com/kamahen/swipl-server-js-client/blob/ec391ed4cb86f30c7e1e0c0c8c511405867a293f/static/simple_client.js), which specifies the option `mode: 'cors'`, so presumably you can turn off CORS with `mode: 'no-cors'`.

However, it’s really easy to have your server handle static requests (search for `http_reply_from_files` in [my server code](https://github.com/kamahen/swipl-server-js-client/blob/ec391ed4cb86f30c7e1e0c0c8c511405867a293f/simple_server.pl)), so I’d recommend using that instead of disabling security features.
