1

我遇到了我的app.yaml文件的問題 - 我有一個單頁應用程序(Angular2應用程序)在AppEngine與python運行時,但深層鏈接不適當路由。這是我的app.yaml文件:AppEngine 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

我假設第二處理程序是什麼做的,但如何編寫我的處理程序將所有內容發送到index.html,但資產除外?這裏是我的dist目錄:

enter image description here

回答

2

是啊,我有同樣的問題。下面是我使用的Angular2應用AppEngine上的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。然而,在此之前,您需要一個映射所有靜態內容的規則,我通過後綴的存在來做我的工作,但另一種方式是通過專門命名所有靜態資產的文件和目錄。

+0

就是這樣,謝謝! –