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

标签 angular google-app-engine single-page-application app.yaml

我的 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/

相关文章:

javascript - 更改 Angular2 主 url

angular - *ng用于显示数据但抛出 'undefined'错误

Angular2 日期管道自动将时区添加到日期

sql - 如何在 Google App Engine 中为 Cloud SQL 实例设置根密码? ["Instance busy"错误信息]

python - Django-social auth KeyError

javascript - 浏览器是否可以检查它是否有 JS 库(无论其来源如何)并使用它?

javascript - 一个响应的多次迭代

具有绑定(bind)数据的 Angular UI 在单击发生之前不会显示

python - appcfg.py 显示您必须以管理员身份登录

Vue.js前端路由与后端flask路由冲突