美文网首页
create-react-app 配置代理

create-react-app 配置代理

作者: 宇少_e010 | 来源:发表于2019-11-18 09:30 被阅读0次

安装http-proxy-middleware:

yarn add http-proxy-middleware

在'src'目录下新建'setupProxy.js'并写入:

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

module.exports = function (app) {
  app.use('/api', proxy({
    target: ' http://172.16.30.166:8000',
    pathRewrite: {
      '^/api': ''
    },
    changeOrigin: true,
  }));
};

重新启动服务

相关文章

网友评论

      本文标题:create-react-app 配置代理

      本文链接:https://www.haomeiwen.com/subject/shrvictx.html