[Vuejs]-CORS policy blocking request from frontend to backend

4👍

You configured the cors module like this:

app.use(cors());

… but that only allows for simple requests.

See the documentation for how to support preflighted requests.

Note, that you wouldn’t be making a preflighted request if it wasn’t for this:

const config = {headers: {'Access-Control-Allow-Origin': '*'}};

… custom request headers require a preflight. Of course, Access-Control-Allow-Origin is a response header so it shouldn’t be on the request in the first place. Remove that.

-1👍

I searched in Github, there is exists a solution with setting crossdomain in axios
const config = {headers: {'Access-Control-Allow-Origin': '*'}}; need to replace with { crossdomain: true }

Here is a link to the answer: https://github.com/axios/axios/issues/853#issuecomment-322954804

👤Max

Leave a comment