我是React初学者,正在基于React文档开发一个项目。
后端api服务器创建为node.js并由PM2管理为http://localhost:4005。前端使用create-react-app创建项目。
为了参考后端的api,我参考这个手册进行了代理设置。
我尝试了 package.json 代理配置和使用 http-proxy-middleware 的手动配置,但没有成功。
代理已配置,但 webpack 开发服务器会调用自身,如下所示。

纱线启动消息(反应)
You can now view client in the browser.
Local: http://localhost:63323/
On Your Network: http://172.30.1.13:63323/
Note that the development build is not optimized.
To create a production build, use yarn build.
[HPM] Error occurred while trying to proxy request /api/getList from localhost:63323 to http://localhost:4005/ (ETIMEDOUT) (https://nodejs.org/api/errors.html#errors_common_system_errors)
Run Code Online (Sandbox Code Playgroud)
浏览器控制台消息:
List.js:19 GET http://localhost:63323/api/getList
net::ERR_CONNECTION_REFUSED
list:1 Uncaught (in promise) TypeError: Failed to fetch
Run Code Online (Sandbox Code Playgroud)
(63323端口是react指定的端口。)
我的项目目录如下所示:

Express 服务器index.js
const express = require('express'); …Run Code Online (Sandbox Code Playgroud)