我用的create-react-app 的版本是 1.4.0  ,是在 yarn eject 之后。

yarn add http-proxy-middleware

 

在 src文件夹下 创建 setipProxy.js 文件 。

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

module.exports = function (app) {
  app.use(
    proxy('/', {
      target: 'http://localhost:3002',
      changeOrigin: true
    })
  )
}

在 config 中的 start.js 中 加入 ,注意添加位置要在  devServer 定义之后。

    require('../src/setupProxy')(devServer);

  重启 服务器,就可以了。

 

相关文章:

  • 2022-12-23
  • 2021-07-23
  • 2021-04-09
  • 2021-07-18
  • 2021-12-20
  • 2021-08-06
  • 2018-08-19
猜你喜欢
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2021-08-11
相关资源
相似解决方案