首页 > 解决方案 > 如何将 create-react-app 部署到 Google Cloud

问题描述

我有一个使用 Expressjs 的前端 create-react-app 和一个后端 API。

我成功地将后端 API 部署到 Google App Engine。

但是现在我需要将 create-react-app 部署到 Google Cloud 并且它变得非常混乱,我尝试 google 了一段时间并且没有真正/推荐的方法。

至少我看到其他人建议以两种方式进行:

  1. 使用谷歌云存储:

    • 运行“npm run build”以创建“build”文件夹

    • 将整个文件夹上传到存储桶

=> 我发现使用这种方式有一个缺点:当我尝试重新加载页面 'url/aboutUs' 时,找不到它。所以我必须回到“url”然后点击关于我们链接

=> 我猜我正在使用的 React Router 不适用于 Google Cloud Storage

  1. 使用谷歌应用引擎

=>人们刚刚谈到使用它,但我找不到任何指南/教程。

那么将 create-react-app 部署到 Google Cloud 的推荐方法是什么?

你能提供一个教程吗?

谢谢。

标签: reactjsgoogle-app-enginegoogle-cloud-platformgoogle-cloud-storagecreate-react-app

解决方案


您只需将 Cloud Storage 存储桶配置index.html404 页面即可。

在此处输入图像描述

对于 Google App Engine,您可以在 build 文件夹中使用serve或设置服务index.html


推荐阅读