Scenario 1: Configure the proxy as follows

Ue-cli3.0 /config/index.js file:

Module. exports = {dev: {proxyTable: {'/ API /**': {target: 'http://10.10.17.64:8082/', changeOrigin: false, secure: false, pathRewrite: { '^/api': '' } } } } }Copy the code

Vue.config.js file for vue-Cli3.0 or later:

Module. exports = {devServer: {proxy: {'/ API /**': {target: 'http://10.10.17.64:8082/', changeOrigin: false, secure: false, pathRewrite: { '^/api': '' } } } } }Copy the code

An error occurred when refreshing the page. Procedure

SyntaxError: Invalid regular expression: //api/**/: Nothing to repeat

/ API /**

Official Documentation

Check out the official WebPack documentation:

www.webpackjs.com/configurati…

The instructions are as follows:

Request to the/API/users will now be agent to request http://localhost:3000/api/users.

If you don’t want to pass/API all the time, you need to rewrite the path:

proxy: {
  "/api": {
    target: "http://localhost:3000",
    pathRewrite: {"^/api" : ""}
  }
}
Copy the code

The correct configuration is as follows

So remove the /** wildcard as a wildcard…

Proxy: {'/ API ': {target: 'http://10.10.17.64:8082/', changeOrigin: false, Secure: false, pathRewrite: {'^/ API ': "'}}}Copy the code

Scenario 2: Configure the proxy as follows

'/birt': {target: 'http://10.10.17.99:6013/', changeOrigin: false, Secure: false, pathRewrite: {'^/birt': '}},Copy the code

An error occurred when refreshing the page. Procedure

The birtCustoms route conflicts with the interface call.

The correct configuration is as follows

'/birt/': {// it is best to add vertical bars to the configuration to prevent birt routes from being called as interfaces. Target: 'http://10.10.17.99:6013/', changeOrigin: false, Secure: false, pathRewrite: {'^/birt/': '}},Copy the code

Extended configuration problem

It is better to prefix all interface calls with/API/to distinguish between interface calls and route jumps.

Otherwise, you can have problems deploying the front end using the IIS server, as documented in another article.

Juejin. Cn/user / 281954…