如何将 create-react-app 部署到 Google Cloud [英] How to deploy create-react-app to Google Cloud

本文介绍了如何将 create-react-app 部署到 Google Cloud的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

  1. 使用 Google 云存储:

    • 运行npm run build"来创建build"文件夹

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

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

=> 我猜我使用的 React Router 不能与 Google Cloud Storage 配合使用

  1. 使用 Google App Engine

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

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

你能提供一个教程吗?

谢谢.

解决方案

您只需要将 Cloud Storage 存储分区配置为

对于 Google App Engine,您可以使用 serve 或设置 在构建文件夹中提供index.html.

I have a frontend create-react-app and a backend API using Expressjs.

I deployed the backend API to Google App Engine successfully.

But now I need to deploy the create-react-app to Google Cloud and it becomes very confusing, I tried to google for a while and there is no true/recommended way for this.

At least I saw that other people suggested doing it in 2 ways:

  1. Using Google Cloud Storage:

    • Run "npm run build" to create the "build" folder

    • Upload this whole folder onto a bucket

=> I see that there is one drawback using this way: When I tried to reload page 'url/aboutUs', it's not found. So I have to go back to 'url' then click the About Us link

=> I guess that the React Router that I'm using is not working with Google Cloud Storage

  1. Using Google App Engine

=> People just talked about using it, but I can't find any guide/tutorial for this.

So what is the recommended way to deploy create-react-app to Google Cloud?

And can you please provide a tutorial for that?

Thanks.

解决方案

You just need to configure the Cloud Storage bucket to serve index.html as the 404 page.

For Google App Engine, you can use serve or set up to serve index.html in the build folder.

这篇关于如何将 create-react-app 部署到 Google Cloud的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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