John Doe
John Doe

Reputation: 423

How can i resolve the No 'Access-Control-Allow-Origin' problem?

I am using Heroku to run my server, and I am using 'cores' at my backend side that wrote in Node.js. I have these commands:

const corsConfig = {
  origin: true,
  credentials: true
};
app.use(cors(corsConfig));
app.options("*", cors(corsConfig));

in my client i am using vue.js:

module.exports = {
    devServer: {
      proxy: {
        '/api': {
          target: '"https://david-matan-recipe-api-server.herokuapp.com/',
          ws: true,
          changeOrigin: true
        }
      }
    }
  }

when I am trying to get some data from my backend with Axios I get this message at my browser:

Access to XMLHttpRequest at 'https://david-matan-recipe-api-server.herokuapp.com/api/recipes/random' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Upvotes: 0

Views: 104

Answers (1)

RedRevi
RedRevi

Reputation: 36

try to set config like this:

const corsConfig = {
  origin: 'http://localhost:8080'
};

Upvotes: 2

Related Questions