问题描述
我正在使用带有快速后端的 create-react-app.我的后端在端口 3001 上运行,前端在开发模式下通过端口 3000 运行.我的 package.json 中有 "proxy": "http://localhost:3001"
并且 api 运行良好.
I'm using create-react-app with an express backend. I have the backend running on port 3001, and the frontend runs through port 3000 when in dev mode. I have "proxy": "http://localhost:3001"
in my package.json and the api works perfectly.
然而,当我使用 yarn build,然后运行 serve -s build
时,根本不会进行 api 调用.我不确定为什么它在生产中不起作用,而在开发中却起作用.
When I use yarn build, however, and then run serve -s build
, the api calls are simply not being made. I'm not sure why it doesn't work in production, when it does in dev.
任何帮助将不胜感激.
推荐答案
代理功能不适用于生产.
The proxy feature isn't meant for production.
这可能有助于进一步解释:https://github.com/facebookincubator/create-react-app/issues/1087#issuecomment-262611096
This might help further explain: https://github.com/facebookincubator/create-react-app/issues/1087#issuecomment-262611096
这篇关于在生产构建中创建 React-App 代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!