Two:

First: this solution can only configure a server proxy across domains

Add: proxy: ‘XXXXX’ // server address to package.json

The address for calling the API here is just your server address.

Second: you can configure the proxy for multiple sets of server environments

Use a third-party library: HTTP-proxy-Middleware

NPM install –save-dev http-proxy-middleware

Create a setupproxy. js file in the SRC directory and write the configuration to the js file:

const { createProxyMiddleware } = require(‘http-proxy-middleware’)

module.exports = function (app) {

app.use(

‘/ API ‘, // specify the request to forward

createProxyMiddleware({

Target: ‘http://localhost:3001’,// Server address

changeOrigin: true,

pathRewrite(path) {

return path.replace(‘/api’, ”);

}

})

);

}

Prefix the invocation path of your business interface with/API:

Last but not least: the server address (baseUrl) of the API call should be your current local address, for example, my local address is: http://localhost:3000, my server address: http://localhost:3001, if the server address as baseUrl, that or cross-domain failure, of course, if you go online, you have to make a logical judgment, with the server address.

The preceding two solutions take effect only after the service is restarted.