如何在App Engine上设置Angular 4 App

时间:2017-06-27 14:15:07

标签: angular google-app-engine google-cloud-platform angular-cli

要在App Engine上托管Angular 4应用程序(使用angular-cli构建),我构建了以下内容:

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

正如您所看到的,我只使用static_files端点,并且根本没有涉及到python应用程序。我这样做是为了在Google Cloud Platform中使用https运行应用。但我发现谷歌文​​档令人困惑,特别是当我不知道可用的工具时。有一个更好的方法吗?这种方法有什么陷阱我应该警惕吗?

1 个答案:

答案 0 :(得分:1)

这些是应用引擎上所需的基本配置

#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