gpt4 book ai didi

node.js - 尝试代理到 : localhost:3000/api on a M1 Macbook 时出错

转载 作者:行者123 更新时间:2023-12-05 02:29:54 30 4
gpt4 key购买 nike

我正在使用 Node.js、React.js 和 MongoDB 开发一个项目。

当我向服务器发送请求时,出现以下错误:

Error occurred while trying to proxy request /api/auth/login from localhost:3000 to 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 上有问题。

任何指导都会对我有很大帮助。

最佳答案

我将 Node.js 的版本更改为 14.9.0,它工作正常。

这些是在互联网上找到的对我不起作用的解决方案:

  • Changing node.js version to other stable version 16 or 18
  • specifying an IPv4 address like this on server (because I can see my server was running on IPv6): server.listen(13882, "0.0.0.0", function() { });
  • Removing proxy entry from the Package.json file
  • Updating to {target: "http://localhost:6000/"} OR {target: "https://localhost:6000/"} OR {target: "http://127.0.0.1:6000"} OR{'http://[::1]:6000'} OR {app.use(proxy("/api/", {target:"http://localhost:6000",secure: false,changeOrigin: true}));}

我在 package.json 文件中有这个条目 "proxy": "http://localhost:6000"

这是我的 setupProxy.js 文件

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

module.exports = function(app) {
app.use(proxy("/api/", { target: "http://localhost:6000" }));
};

关于node.js - 尝试代理到 : localhost:3000/api on a M1 Macbook 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72007843/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com