ScaffoldHub - v2
  • Introduction
  • Modeling
    • Two-way Relationships
  • Setup
    • Backend
    • Frontend
    • File Storage
    • Emails with SendGrid
    • Payments with Stripe
  • Debugging
  • Deployment
    • Database
      • SQL
      • MongoDB
    • Backend
      • Google Cloud - App Engine
      • Google Cloud - Run
      • Under construction...
    • Frontend
      • Firebase Hosting
      • Heroku w/ Subdomains
      • Under construction...
  • Features
    • Projects
    • Preview
    • Tenants
      • Single-Tenant
      • Multi-Tenant
      • Multi-Tenant (w/ subdomains)
    • Payments
    • Security
    • Authentication
      • Sign-in and Sign-up
      • Invitation
      • Password Reset
      • Password Change
      • Email Verification
    • Audit Logs
    • Settings
    • Internationalization (I18n)
    • Entity
      • Form
      • Filter and List
      • Export
      • Import
    • API Documentation
  • Architecture
    • Security
    • File Storage
    • Internationalization (I18n)
    • Payments
    • Typescript Support
    • Rate limiting
    • Technologies Versions
    • Under construction...
  • Recipes
    • Testing the API with Postman
    • Enterprise sign-in with WorkOS
    • Under construction...
  • Support
  • Changelog
    • Documentation
    • Scaffolds
  • Custom Development
  • Legacy Scaffolds
  • Go to ScaffoldHub
Powered by GitBook
On this page
  • Requirements
  • App Engine Files
  • Git Ignore
  • Google Cloud Project
  • Enable billing
  • Google SDK
  • Build
  • Replace the start script
  • Deployment Script

Was this helpful?

  1. Deployment
  2. Backend

Google Cloud - App Engine

PreviousBackendNextGoogle Cloud - Run

Last updated 4 years ago

Was this helpful?

is a fully managed serverless platform.

Requirements

  • (if payments are enabled)

  • (Google Cloud Storage is preferable)

  • (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

runtime: nodejs10
instance_class: F4_1G

env_variables:
  # MongoDB only
  DATABASE_CONNECTION: ''
  DATABASE_TRANSACTIONS: false
  # END - MongoDB only

  # SQL only
  DATABASE_USERNAME: 'postgres'
  DATABASE_DIALECT: 'postgres'
  DATABASE_PASSWORD: ''
  DATABASE_DATABASE: 'production'
  DATABASE_HOST: ''
  DATABASE_LOGGING: 'true'
  # END - SQL only

  DATABASE_INDIVIDUAL_CONNECTIONS_PER_REQUEST: 'false'
  TENANT_MODE: 'multi'
  AUTH_JWT_SECRET: 'GENERATE_SOME_RANDOM_UUID_HERE'
  AUTH_JWT_EXPIRES_IN: '7 days'
  SENDGRID_EMAIL_FROM: ''
  SENDGRID_KEY: ''
  SENDGRID_TEMPLATE_EMAIL_ADDRESS_VERIFICATION: ''
  SENDGRID_TEMPLATE_INVITATION: ''
  SENDGRID_TEMPLATE_PASSWORD_RESET: ''
  FRONTEND_URL: 'https://domain.com:<port>'
  FRONTEND_URL_WITH_SUBDOMAIN: 'https://[subdomain].domain.com:<port>'
  BACKEND_URL: 'https://YOUR_SERVER_URL/api'
  PLAN_STRIPE_SECRET_KEY: ''
  PLAN_STRIPE_WEBHOOK_SIGNIN_SECRET: ''
  PLAN_STRIPE_PRICES_GROWTH: ''
  PLAN_STRIPE_PRICES_ENTERPRISE: ''
  FILE_STORAGE_PROVIDER: 'gcp'
  FILE_STORAGE_BUCKET: ''
  GOOGLE_CLOUD_PLATFORM_CREDENTIALS: '{ "type": "service_account", "project_id": "...", "private_key_id": "...", "private_key": "...", "client_email": "...", "client_id": "...", "auth_uri": "...", "token_uri": "...", "auth_provider_x509_cert_url": "...", "client_x509_cert_url": "..." }'
  AWS_ACCESS_KEY_ID: ''
  AWS_SECRET_ACCESS_KEY: ''

FRONTEND_URL and FRONTEND_URL_WITH_SUBDOMAIN

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

node_modules/
/data
dist/
app-engine.staging.yml
app-engine.production.yml

Files ignored by Git are different from the ones ignored by the Google Cloud Platform, so you must create a .gcloudignore file.

backend/.gcloudignore

.gcloudignore
.git
.gitignore
node_modules/

Google Cloud Project

Create a new project for the production environment. To create a staging environment the steps are the same.

Enable billing

Google SDK

Sign in to your account calling gcloud auth login.

Build

Before deploying, you must install the dependencies and build the application:

npm install
npm run build

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

{
  "scripts": {
    ...
    "start": "node ./dist/server.js",
    "start:watch": "nodemon --watch \"src/**/*.ts\" -e ts,json --exec \"ts-node --transpile-only ./src/server.ts\"",
    ...
  }
}

Deployment Script

To deploy the application you must run this command:

gcloud app deploy app-engine.staging.yaml --project PROJECT-ID

Let's create deployment scripts to automate this:

backend/package.json

{
  ...
  "scripts": {
    ...
    "deploy:staging": "npm run build && gcloud app deploy app-engine.staging.yaml --project PROJECT-ID-STAGING",
    "deploy:production": "npm run build && gcloud app deploy app-engine.production.yaml --project PROJECT-ID-PRODUCTION"
  }
  ...
}

Now run:

npm run deploy:staging
// or
npm run deploy:production

Set this to your URL (if you have one already).

Go to and create an account.

The project needs the billing enabled: .

Install the .

hosted frontend
https://cloud.google.com/
https://cloud.google.com/billing/docs/how-to/modify-project
https://cloud.google.com/sdk
Google Cloud App Engine
Emails with Sendgrid
Payments with Stripe
Database
File Storage