gpt4 book ai didi

angular - 单页应用的 AppEngine app.yaml 配置

转载 作者:太空狗 更新时间:2023-10-29 18:05:55 25 4
gpt4 key购买 nike

我的 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/(.*)

直接进入深层链接时出现以下错误:

enter image description here

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

enter image description here

最佳答案

是的,我遇到了同样的问题。这是我在 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/\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 。但是,在此之前,您需要一个映射所有静态内容的规则,我通过后缀的存在来做我的,但另一种方法是专门命名属于静态 Assets 的所有文件和目录。

关于angular - 单页应用的 AppEngine app.yaml 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43531452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com