Rob
Rob

Reputation: 3746

How to Setup Angular 4 App on App Engine

To host an Angular 4 app (built with angular-cli) on App Engine I built the following:

service: stage
runtime: python27
api_version: 1
threadsafe: true

skip_files:
- ^(?!dist)  # Skip any files not in the dist folder

handlers:
# Routing for bundles to serve directly
- url: /((?:inline|main|polyfills|styles|vendor)\.[a-z0-9]+\.bundle\.js)
  secure: always
  redirect_http_response_code: 301
  static_files: dist/\1
  upload: dist/.*

# Routing for a prod styles.bundle.css to serve directly
- url: /(styles\.[a-z0-9]+\.bundle\.css)
  secure: always
  redirect_http_response_code: 301
  static_files: dist/\1
  upload: dist/.*

# Routing for typedoc, assets and favicon.ico to serve directly
- url: /((?:assets|docs)/.*|favicon\.ico)
  secure: always
  redirect_http_response_code: 301
  static_files: dist/\1
  upload: dist/.*

# Any other requests are routed to index.html for angular to handle so we don't need hash URLs
- url: /.*
  secure: always
  redirect_http_response_code: 301
  static_files: dist/index.html
  upload: dist/index\.html
  http_headers:
    Strict-Transport-Security: max-age=31536000; includeSubDomains
    X-Frame-Options: DENY

As you can see I am only using the static_files endpoints, and there is not a python app involved at all. I did this in order to have an app running under https in Google Cloud Platform. But I find the Google documentation to be confusing, especially when I don't know what tools are available. Is there a better way to do this? Are there any pitfalls with this method I should be wary of?

Upvotes: 1

Views: 753

Answers (1)

Ashish Kumar
Ashish Kumar

Reputation: 581

These are the basic configuration which is needed on app engine

#Configuration of runtime parameters
runtime: custom
env: flex
service: ui-version

handlers:
- url: /.*
  script: this field is required, but ignored
  secure: always  # Require HTTPS

health_check:
  enable_health_check: False
  check_interval_sec: 5
  timeout_sec: 4
  unhealthy_threshold: 2
  healthy_threshold: 2

manual_scaling:
  instances: 1

resources:
  cpu: 1
  memory_gb: 4.0
  disk_size_gb: 20

Upvotes: 1

Related Questions