单页应用的 AppEngine app.yaml 配置

AppEngine app.yaml config for single page apps

我的 app.yaml 文件有问题 - 我在 AppEngine 上有一个具有 python 运行时的单页应用程序(Angular2 应用程序),但是深度 links没有适当地路由。这是我的 app.yaml 文件:

runtime: python27
api_version: 1
threadsafe: true

skip_files:
- ^(.*/)?app\.yaml
- ^(.*/)?app\.yml
- ^(.*/)?#.*#
- ^(.*/)?.*~
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*/RCS/.*
- ^(.*/)?\..*
- ^(.*/)?tests$
- ^(.*/)?test$
- ^test/(.*/)?
- ^COPYING.LESSER
- ^README\..*
- \.gitignore
- ^\.git/.*
- \.*\.lint$
- ^fabfile\.py
- ^testrunner\.py
- ^grunt\.js
- ^node_modules/(.*/)?
- ^src/(.*/)?
- ^e2e/(.*/)?

handlers:
- url: /
  static_files: dist/index.html
  upload: dist/index.html

- url: /(.*)
  static_files: dist/
  upload: dist/(.*)

直接进入深度 link 时出现以下错误:

我假设第二个处理程序正在执行此操作,但是如何编写我的处理程序以将除资产之外的所有内容发送到 index.html?这是我的 dist 目录:

啊是的,我遇到了同样的问题。这是我在 Appengine 上用于 Angular2 应用程序的 app.yaml:

runtime: python27
api_version: 1
threadsafe: true

handlers:

- url: /api/.*
  script: main.app

# All files that can be compiled in angular. Luckily, they all have suffixes.
- url: /(.*\.(css|eot|gz|html|ico|js|map|png|svg|ttf|woff|woff2))
  static_files: ../client/dist/
  upload: ../client/dist/(.*\.(css|eot|gz|html|ico|js|map|png|svg|ttf|woff|woff2))

# Site root, plus anything else, like deep urls
# Make this be secure, otherwise oauth redirect won't work if they want to us with http://
- url: /.*
  static_files: ../client/dist/index.html
  upload: ../client/dist/index.html
  secure: always
  expiration: "15m"

libraries:
- name: webapp2
  version: "2.5.2"

要处理深层链接,您需要在末尾设置一个包罗万象的规则以始终提供 index.html 。但是,在此之前,您需要一个映射所有静态内容的规则,我通过后缀的存在来做我的,但另一种方法是专门命名属于静态资产的所有文件和目录。