【问题标题】:AppEngine app.yaml config for single page apps单页应用的 AppEngine app.yaml 配置
【发布时间】:2017-09-17 19:00:13
【问题描述】:

我的 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 目录:

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 谢谢,您的解决方案节省了我的时间。
    猜你喜欢
    • 2015-06-25
    • 1970-01-01
    • 2011-07-06
    • 2011-05-12
    • 1970-01-01
    • 2017-06-23
    • 2011-06-28
    • 2011-08-24
    • 1970-01-01
    相关资源
    最近更新 更多