[英]Error occurred while proxying request localhost:3000/api/product to http://localhost:5000/
We are trying to create an simple eCommerce app using Typescript, express and nextjs.我们正在尝试使用 Typescript、express 和 nextjs 创建一个简单的电子商务应用程序。
When we make a request to it, it throws the following error.当我们向它发出请求时,它会抛出以下错误。
[HPM] Error occurred while proxying request localhost:3000/api/product to http://localhost:5000/ [ECONNREFUSED] ( https://nodejs.org/api/errors.html#errors_common_system_errors )
[HPM] 将请求 localhost:3000/api/product 代理到 http://localhost:5000/ [ECONNREFUSED] ( https://nodejs.org/api/errors.html#errors_common_system_errors ) 时出错
My friend is using Windows, and code is working on his PC but not on my Ubuntu desktop.我的朋友使用的是 Windows,代码在他的 PC 上运行,但在我的 Ubuntu 桌面上运行。
I tried killing the port like below.我尝试像下面这样杀死端口。 It also kills the port but this does not help.
它也会杀死端口,但这无济于事。
$ sudo lsof -t -i:5000
6033
$sudo kill -9 6033
$sudo lsof -t -i:3000
6101
$sudo kill -9 6101
Proxy server is listening at server.js file as:代理服务器正在监听 server.js 文件:
const express = require('express');
const next = require('next');
const { createProxyMiddleware } = require('http-proxy-middleware');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app
.prepare()
.then(() => {
const server = express();
// apply proxy in dev mode
if (dev) {
server.use(
'/api',
createProxyMiddleware({
target: 'http://localhost:5000',
changeOrigin: true,
})
);
}
server.all('*', (req, res) => {
return handle(req, res);
});
server.listen(3000, (err) => {
if (err) throw err;
console.log('> Ready on http://localhost:5000');
});
})
.catch((err) => {
console.log('Error', err);
});
Found the solution.找到了解决办法。
I have ignore node_module and upload folder in .gitignore我忽略了node_module和 .gitignore 中的上传文件夹
I forgot to add the folder after cloning.克隆后我忘了添加文件夹。 So, it was showing proxy error.
所以,它显示代理错误。
After I add upload folder error was resolved.添加上传文件夹后,错误已解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.