Search code examples
reactjsgoogle-app-enginegoogle-cloud-platformgoogle-cloud-storagecreate-react-app

How to deploy create-react-app to Google Cloud


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.


Solution

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

    enter image description here

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