NPM run Dev has cross-domain problems with local debugging

Cross-domain problems occur during localhost:8080 debugging, as shown in the following figure:

My project uses WebPack as a front-end automation build tool that can be configured across domains in Webpack-dev-server. Webpack-dev-server is a small NodeJS server based on the Express framework for listening and packaging and compiling static resources in real time. One of the attributes is proxy, which is used to configure the proxy request interface.

Paths assetsSubDirectory: 'static', assetsPublicPath: '/', { '/apis': { target: 'http://dev.daishutijian.com', changeOrigin: true, pathRewrite: { '^/apis': ''}}}, // Various Dev Server Settings host: '0.0.0.0', // Can be overwritten by process.env.host port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined ... },Copy the code

http://dev.daishutijian.com is mapped to ^ / apis

Const API_PATH = "apis/apps/ API /"; function getOrderList(vm) { let url = API_PATH + 'user/order_list'; // # http://dev.daishutijian.com/apps/api/user/order_list return new Promise((resolve, reject) => { Vue.http.get( url, { emulateJSON: true }, ).then((res) => { resolve(res.data); }).catch((res) => { console.log('warn'); })})}Copy the code

The proxy was set up. The request succeeded