在生产版本中创建反应应用程序代理 [英] Create-React-App Proxy in Production Build

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

问题描述

我正在使用带有快速后端的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

这篇关于在生产版本中创建反应应用程序代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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