Access to XMLHttpRequest at from origin blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present


This Content is from Stack Overflow. Question asked by Channel Supporter

I was adjusting my game locally but suddenly I were getting CORS errors.
So I switched to Github where I had a working copy without any changes/adjustments but somehow even that wasn’t working anymore.

My site:

When I check the Console log it shows me this:

Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


I’ve been using socket io V.2.3 and had to enable CORS manually via this code:

const http = require("http");
const socket_io = require("");

const httpServer = http.createServer();
const io = new socket_io.Server(httpServer, {
  cors: {
    origin: "",
//        origin: "",
//        origin: "",
//        origin: "",
        methods: ["GET", "POST"]

I tried with different links but none of them work…

I also found this code snippet:

I have two questions though, do I have to replace the with my netifly or heroku domain?
And where do I have to put in this code? In my server.json or index.html?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?