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

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

问题描述

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


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

b
$ b

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

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


  1. 使用Google云端存储:




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


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

    • b
      $ b

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



      =>我想我正在使用的React路由器不能与Google Cloud存储


      1. 使用Google App Engine

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

      所以推荐的部署方式是什么?创建反应 - 谷歌云应用程序?



      您可以请提供一个教程吗?

      谢谢。

      解决方案

      您只需将Cloud Storage存储桶配置为



      对于Google App Engine,您可以使用服务或设置 nginx 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天全站免登陆