本文介绍了单页应用程序的AppEngine app.yaml配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的app.yaml文件遇到问题-我的AppEngine上有一个单页应用程序(Angular2应用程序),带有python运行时,但是深层链接未正确路由。这是我的app.yaml文件:

I'm having trouble with my app.yaml file - I have a single-page app (Angular2 app) on AppEngine with a python runtime, but the deep links aren't appropriately routed. Here's my app.yaml file:

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

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

I get the following error when going directly to a deep link:

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

I'm assuming that the second handler is what's doing it, but how do I write my handlers to send everything to index.html except for assets? Here's my dist directory:

推荐答案

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

Ah yes, I had the same problem. Here's the app.yaml that I'm using for an Angular2 app on Appengine:

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。但是,在此之前,您需要一个映射所有静态内容的规则,我正在通过添加后缀来做到这一点,但是另一种方法是通过专门命名所有属于静态资产的文件和目录。

To handle deep links, you need a catch-all rule at the end to always serve index.html . However, before that, you need a rule which maps all your static content, I'm doing mine by the presence of a suffix, but another way you could do it is by specifically naming all the files and directories that are your static assets.

这篇关于单页应用程序的AppEngine app.yaml配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:10