reactjs - 如何将 create-react-app 部署到 Google Cloud
问题描述
我有一个使用 Expressjs 的前端 create-react-app 和一个后端 API。
我成功地将后端 API 部署到 Google App Engine。
但是现在我需要将 create-react-app 部署到 Google Cloud 并且它变得非常混乱,我尝试 google 了一段时间并且没有真正/推荐的方法。
至少我看到其他人建议以两种方式进行:
使用谷歌云存储:
运行“npm run build”以创建“build”文件夹
将整个文件夹上传到存储桶
=> 我发现使用这种方式有一个缺点:当我尝试重新加载页面 'url/aboutUs' 时,找不到它。所以我必须回到“url”然后点击关于我们链接
=> 我猜我正在使用的 React Router 不适用于 Google Cloud Storage
- 使用谷歌应用引擎
=>人们刚刚谈到使用它,但我找不到任何指南/教程。
那么将 create-react-app 部署到 Google Cloud 的推荐方法是什么?
你能提供一个教程吗?
谢谢。
解决方案
您只需将 Cloud Storage 存储桶配置为index.html
404 页面即可。
对于 Google App Engine,您可以在 build 文件夹中使用serve或设置nginx来服务index.html
。
推荐阅读
- symfony - 更新奏鸣曲核心后的错误奏鸣曲.core.form.type.*
- mql4 - 以编程方式更改策略测试器中的时间范围
- java - 如何将数组中的随机数分配给值?
- datagridview - DataGridView 数据绑定组合框显示的文本在鼠标悬停时消失
- javascript - 如何使用脚本标签为远程 React 应用程序提供服务?
- laravel - 试图了解 Laravel 的 Passport 对 DB 中 5 个表的需求以及为什么不在 .env 中
- c# - 在不影响驱动器号的情况下清理 C# 中的文件路径
- c# - 用于数据库初始化的 C# 条件编译的替代方法
- ios - iOS从短信自动填充用户名和密码
- wordpress - Woocommerce / wpml 添加不同版本的相同货币