Vue devServer proxy is not helping, I still get CORS error
10,339
It looks like the problem was with the axios configurations.
I had this definition: axios.defaults.baseURL = "http://localhost:8080/api";
I changed it to axios.defaults.baseURL = "api";
and it works.
module.exports = {
...
devServer: {
proxy: {
"^/api": {
target: url,
ws: true,
changeOrigin: true
}
}
},
}
Related videos on Youtube
Author by
Tomer
Updated on October 14, 2022Comments
-
Tomer over 1 year
I'm using @vue/cli 3.x and in my vue.config.js I have this:
devServer: { proxy: { "/api": { ws: true, changeOrigin: true, target: "http://localhost:8080" } } }
But I keep getting CORS error:
Access to XMLHttpRequest at 'http://localhost:8080/api' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Any idea?
-
Tomer over 4 years@dotNET - actually yes :), apparently I had some Axios configurations that were ignoring the proxy. my dev server config looks like this:
devServer: { proxy: { "^/api": { target: url, ws: true, changeOrigin: true } } },
-
-
anna over 4 yearsIn what file do you exactly add this
axios.defaults.baseURL = "api"
? -
Tomer over 4 yearsI have axios.config.js file which i import in my main file, but it doesn't really matter what you name it
-
ibn_Abubakre over 2 yearsYup, this was very useful. Thanks a lot