我的app.yaml文件出现问题 - 我在AppEngine上有一个带有python运行时的单页应用程序(Angular2应用程序),但深度链接没有正确路由。这是我的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/\1
upload: dist/(.*)
直接进入深层链接时出现以下错误:
我假设第二个处理程序正在执行它,但是如何编写处理程序以将所有内容发送到index.html除资产外?这是我的dist目录:
答案 0 :(得分:7)
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/\1
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提供服务。但是,在此之前,您需要一个映射所有静态内容的规则,我通过后缀的存在来实现,但另一种方法是通过专门命名作为静态资产的所有文件和目录。