Vue-cli3 proxy cross-domain error report

proxy: "http://localhost:4000" this tells the development server to proxy any unknown requests (requests that do not match the static file) to http://localhost:4000.

my understanding of this sentence is that any request will be forwarded to the address http://localhost:4000.

// vue.config.js
devServer: {
    proxy: "http://localhost:3000/"
  },

// App.vue
axios.get("http://localhost:3000/test");

I think it succeeded, but the above code will report a cross-domain failure
Access to XMLHttpRequest at "http://localhost:3000/api/test" from origin" http://192.168.0.7:8080" has been blocked by CORS policy: No "Access-Control-Allow-Origin" header is present on the requested resource.

then I change vue.config.js to the following code

proxy: {
      "/": {
        target: "http://localhost:3000/",
        changeOrigin: true
      }

in fact, this code can be cross-domain in cli2. I think these two pieces of code have the same meaning, and now I don"t know how to change the code after reading the document.

Jun.10,2022

suddenly become mentally retarded. Should write relative path


No backend code is required to set header ('Access-Control-Allow-Origin?

Menu