127  
查询码:00001024
Http-proxy-middleware安装报错:proxy is not a function
来源:https://blog.csdn.net/balics/article/details/104479641
作者: 朱凡 于 2020年04月19日 发布在分类 / FM组 / FM_App 下,并于 2020年04月19日 编辑
阅读 阅读数 读数 来自 middleware 解决 问题 http-proxy-middleware function 程序

Http-proxy-middleware安装报错:proxy is not a function


Create-react-app建的项目,需要访问多个跨域接口,按照CRA的官方文档安装了http-proxy-middleware后,进行了下面的配置:

const proxy = require('http-proxy-middleware');
module.exports = function(app) {
 app.use(
  '/org',
  proxy({
   target: 'http://localhost:5000',
   changeOrigin: true,
  })
 );
 app.use(
  '/sys',
  proxy({
   target: 'http://localhost:5001',
   changeOrigin: true,
  })
 );
};

然后启动报错:proxy is not a function
在这里插入图片描述
后查看了http-proxy-middleware的官方文档,发现最新的1.0.0版本已经对模块的引用作了明确的要求

0.x.x版本的引用方式

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

1.0.0版本的引用方式

const { createProxyMiddleware } = require('http-proxy-middleware');

修改了配置代码后即可工作。



 推荐知识

 历史版本

修改日期 修改人 备注
2020-04-19 10:42:58[当前版本] 朱凡 创建版本

 附件

附件类型

PNGPNG

知识分享平台 -V 4.8.7 -wcp