试图代理到:Localhost:M1 MacBook上的3000/API时发生错误
我正在使用Node.js,React.js和MongoDB进行一个项目。
当我将请求发送到服务器时,我会收到以下错误:
尝试代理请求
/api/auth/login/login/code>
localhost:3000
tohttp:// http:// localhost:6000
(( econnreset)。
我的客户端在端口3000(端口6000)运行。这是客户端代理中间件设置代码:
const proxy = require("http-proxy-middleware");
module.exports = function(app) {
app.use(proxy("/api/", { target: "http://localhost:6000", "secure": "false" }));
};
我尝试使用127.0.0.1
localhost
的内置,但无效。
该项目在Windows笔记本电脑中正常工作。但是,M1 Mac有问题。
任何指导都会对我有很大的帮助。
I am working on a project with Node.js, React.js and MongoDB.
When I send request to server, I get the following error:
Error occurred while trying to proxy request
/api/auth/login
fromlocalhost:3000
tohttp://localhost:6000
(ECONNRESET).
I have my client running at port 3000, server at port 6000 locally. Here is the client side proxy middleware setup code:
const proxy = require("http-proxy-middleware");
module.exports = function(app) {
app.use(proxy("/api/", { target: "http://localhost:6000", "secure": "false" }));
};
I have tried using 127.0.0.1
inplace of localhost
, but didn't work.
The project works fine in Windows laptop. But, it is having problem with M1 Mac.
Any guidance would be of great help to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用M1遇到了相同的错误。
该代码开始适合我工作。
http:// localhost:3000/
- >http://127.0.0.0.1:3000/
server.js
packege.json
服务器在“ http://127.0.0.0.0.1.1:3000/” a href =“ https://create-react-app.dev/” rel =“ noreferrer”> create-react-app-app-app (“ active-scripts”:“:“^5.0.1”)
I got the same error using M1.
This code started working correctly for me.
http://localhost:3000/
->http://127.0.0.1:3000/
server.js
packege.json
Server at "http://127.0.0.1:3000/" - default configuration for create-react-app ("react-scripts": "^5.0.1")
我将Node.js的版本更改为14.9.0,并且可以使用。
这些是互联网上发现的解决方案,对我不起作用:
我在package.json文件
“代理”中具有此条目:“ http:// localhost:6000”
这是我的setUpproxy.js文件
I changed the version of Node.js to 14.9.0 and it worked.
These are the solutions found in the internet that didn't work for me:
I have this entry in package.json file
"proxy": "http://localhost:6000"
This is my setupProxy.js file