For people like me who have only used a static host like Amazon S3 before, deploying React app on Google App Engine is a challenge. For all the references I found it looks straightforward and easy to deploy a React app, yet I still struggled for 2 days. Here is how I did it, with the things I realized by logs and tries and errors.
GAE is not a static host; it's a virtual machine
So you can't just push the build. You have to serve it, like starting a development server. So the next problem is, how?
With default config, GAE only executes two scripts when deploying
They are npm install
and npm start
.
Like I mentioned before, for merely starting a server for React, these two seems enough. Then I found out it's not, because default npm start
provided by Create-React-App, which equals to node scripts/start.js
if you check out package.json
, takes much time, and it's long enough to make the app not working. So we need a faster way to serve it.
Serve can do the trick
Notice serve needs static files to run, so we need to build it first. Since GAE only runs two scripts, and building takes some time too, so I bound it to postinstall
instead of prestart
. By this way, GAE automatically builds right after it installs dependencies.
You can also use some host framework (like express) to do the hosting and routing stuff too.
Config the port
React development server default port is 3000, and serve's is 5000, while GAE uses 8080.
The scripts in package.json
I used when finally successfully deployed looks like this:
"script": {
"postinstall": "npm run build",
"start": "serve -l 8080 -s build"
}
You need to configure app.yaml too, but I think many resources is talking about how to do it.
I hope this helps!
ArchiveA Redemption Three Years Later
CD PROJEKT RED made a promise about Night City, which they broke. Three years later they had another attempt, and to me, it was their redemption.
January 13, 2025
S14 Recap
I did not play a lot of league during 2024, but I had a few unforgettable moments nonetheless.
January 7, 2025
Thoughts on Building a Game with XState
After hearing about XState's good reputation for years, I used it to build the prototype for my game. These are my thoughts.
January 4, 2025
Under the Hood: Diablo II Item Generation
A system design research turned into a reconciliation with a game I didn't know I was so in love with, so I wrote a research note to express my appreciation.
November 8, 2024
Site Patch Notes: 2024 Redesign
The 2024 redesign is finally here! I went on a journey of learning editorial design, and did an overhaul to this site's design, both functionality-wise and visual-wise.
August 18, 2024