Google Cloud - App Engine
Google Cloud App Engine is a fully managed serverless platform.
Requirements
Payments with Stripe (if payments are enabled)
File Storage (Google Cloud Storage is preferable)
Database (MongoDB Atlas hosted at GCP or Google SQL are preferable)
App Engine Files
The configuration for the App Engine server is placed at the app-engine.environment.yaml file.
backend/app-engine.production.yaml
backend/app-engine.staging.yaml
FRONTEND_URL and FRONTEND_URL_WITH_SUBDOMAIN
Set this to your hosted frontend URL (if you have one already).
BACKEND_URL
Set this one with the URL you received after the first deployment. Don't forget to add the /api suffix. It will be something like https://project-id.appspot.com/api.
Git Ignore
Because that the app-engine.environment.yaml contains sensitive information, is recommended to add it to .gitignore.
backend/.gitignore
Files ignored by Git are different from the ones ignored by the Google Cloud Platform, so you must create a .gcloudignore file.
backend/.gcloudignore
Google Cloud Project
Go to https://cloud.google.com/ and create an account.
Create a new project for the production environment. To create a staging environment the steps are the same.
Enable billing
The project needs the billing enabled: https://cloud.google.com/billing/docs/how-to/modify-project.
Google SDK
Install the https://cloud.google.com/sdk.
Sign in to your account calling gcloud auth login
.
Build
Before deploying, you must install the dependencies and build the application:
Replace the start script
App Engine uses the start script to run the application, but our start script also compiles and watches for changes, which isn't needed for production.
Let's replace the original for npm run start:watch
, that we will run on localhost, and leave the npm start
for the App Engine.
backend/package.json
Deployment Script
To deploy the application you must run this command:
Let's create deployment scripts to automate this:
backend/package.json
Now run:
Last updated