The new create-react-app + webpack4 cross-domain

src / setupProxy.js create a file

const proxy = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(proxy('/api', { 
       target: 'https://www.easy-mock.com/api/' ,
       secure: false,
       changeOrigin: true,
       pathRewrite: {
        "^/api": "/"
       },
      //  http://www.easy-mock.com'
       // cookieDomainRewrite: "http://localhost:3000"
    }));
};

if not

package.json 

Add to

 "proxy":"http://youAddr.com"

If not enough

Add to

"proxy":{
   "/rank/**":{
      "target":"http://m.kugou.com",
      "changeOrigin": true
    }
  }

 

Guess you like

Origin www.cnblogs.com/dianzan/p/11344476.html