Webpack agents solve cross-domain problems

  1. previously co-debugged with the backend, and worked as an agent locally to solve the cross-domain problem. Now you need to put it on the service to find that it failed to send. The request sent also comes with the API field of the agent
  2. .
  3. configure as follows
    proxyTable: {
      "/api": {
        // target: "",
        target: "xxx,xxx,xxx,xxx",
        changeOrigin: true,
        pathRewrite: {
          "^/api": ""
        }
      }
    },

because of the joint call with two backends, it is not mandatory to add a fixed proxy to all requests, so the URL of the request is written like this

let url = "/api/FileStation"; 1
let url = "/api2/FileStation"; 2

I tried to set target: to an empty string in the configuration, thinking that this would allow

"/api/FileStation" =>"/FileStation"

the actual release is not good, please ask Daniel to guide you how to do it.

Jul.27,2021

this is called locally to let the backend solve cross-domain solutions


Thank you for your guidance. It turns out that proxies can only work locally.
I modified and set up a global proxy in main.js

Axios.defaults.baseURL = '/api1'; 
Axios.defaults.baseURL = '/api2';

in this way, url does not need to add the'/ api' field, and whoever debugs needs to comment out the other, so that you do not have to delete the'/ api' in the url one by one when you need to package it to the server.

The

proxy is only effective locally. If you go online, let the backend configure cors cross-domain. You can let the backend configure cors cross-domain settings under Baidu, and then configure it


you can use this locally, but you can't put it online. If you know how this configuration agent works, you will know that such code will not work online. Online cross-domain can discuss a solution with the backend, and it is usually an easy way to let them configure the server and release the permissions.


Uh, who can explain that proxy, can't be used online

Menu