localhost:3000安装http代理中间件后无法访问此站点



我正在构建一个时事通讯注册表单,该表单使用.netlify lambda将我提交的表单发送给Mailchimp。我安装了http代理中间件来帮助前端找到netlify lambda文件夹。在我的React启动脚本下面写下代理设置代码后,它停止了工作。下面的代理设置似乎正在干扰localhost:3000。

我的代理设置看起来像这个

const proxy = require('http-proxy-middleware');
module.exports = function(app) {
console.log('Using proxy...')
app.use(proxy('/.netlify/functions/', { 
target: 'http://localhost:9000/',
"pathRewrite": {
"^\.netlify/functions": ""
}
}));
};

如果目标是localhost:9000,为什么它会干扰localhost:3000?当我启动Lambda服务器时,它会显示:Lambda server is listening on 9000

我在尝试编译我的客户端应用程序时也遇到了这个错误。crbug/1173575,非JS模块文件已弃用

简短回答(适用于@lachnroll和任何可能遇到相同问题的人(:

请使用const { createProxyMiddleware } = require("http-proxy-middleware")app.use(createProxyMiddleware('/.netlify/functions/' ...)...),而不是使用const proxy = require('http-proxy-middleware');app.use(proxy("/.netlify/functions/" ...)...),它应该可以工作。

长型:

我遇到了同样的";无法联系到";当使用http代理中间件(2.0.3(时,React项目中的事情,直到我更改constproxy=require('http-proxy-midleware'(proxy("/.netlify/functions/"…(const{createProxyMiddleware}=require("http代理中间件"(app.use(createProxyMiddleware('/.netlify/functions/'…(,我认为代理已被删除,请参阅:https://github.com/chimurai/http-proxy-middleware#readme

最新更新