Disable CORS, need help

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’ from origin ‘’ 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 :

[ methods([get,post,delete])

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

thanks gona keep trying

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

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

1 Like

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,

fetch() is the modern replacement for XMLHttpRequest(). There is an example of using fetch in my client code, 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), so I’d recommend using that instead of disabling security features.

1 Like