在生产构建中创建 React-App 代理 [英] Create-React-App Proxy in Production Build

查看:29
本文介绍了在生产构建中创建 React-App 代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有快速后端的 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 代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆