Invalid mpvue+iview weapp proxyTable proxy configuration

mpvue+iview weapp developer Mini Program, configure proxyTable
proxyTable: {

in the index under the config folder
  "/api": {
    target: "https://xxxxx/api",
    changeOrigin: true,
    secure: false,
    pathRewrite: {
      "^/api": ""
    }
  }
},

where the request is encapsulated
fly.config.baseURL ="/ api"
but the request will report an error

Jul.15,2021

solve

  1. modify fly baseURL
fly.config.baseURL = 'http://localhost:xxxx'; // => dev
  1. modify the webpack configuration, that is, the proxyTable you described (this is actually the property name that appears after mpvue overrides the webpack configuration file)
pathRewrite: {
  'http://localhost:xxxx': 'http://yourserver.com' // => api
}

reason

  • the content of the error is illegal url.
  • your request address has only a path and no domain name, which must be illegal. That's why webpack didn't add a domain name when it was packaged and rewritten
Menu