0

我目前正在使用angular-CLI生成的angular4投影來創建項目結構,並且我能夠使用ng-serve服務它並開發並查看更改。現在我想將它移動到我自己的後端,使用谷歌應用程序引擎和webApp2並使用dev_appserver.py app.yaml運行它。目前,我可以通過執行ng-build並從dist文件夾中提供文件來完成這項工作。我想這樣做,所以我可以輕鬆地進行更改,但不必等待每次重建。谷歌上的Angular4和WebApp2應用引擎

回答

1

您可以在角度上使用環境,以指向您的Python休息服務和另一個環境生產。

例子:

enviroment.ts

 
export const environment = { 
    production: false, 
    urlServices: 'http://190.52.112.41:8075' 
}; 

enviroment.prod.ts

 
export const environment = { 
    production: true, 
    urlServices: 'http://localhost:8080' 
}; 

這樣,你不需要編譯,測試你aplication因爲angular始終會指向你的python應用程序。

0

使用標準的App Engine配置的app.yaml的解決方案:

service: stage 
runtime: python27 
api_version: 1 
threadsafe: true 

skip_files: 
- ^(?!dist) # Skip any files not in the dist folder 

handlers: 
# Routing for bundles to serve directly 
- url: /((?:inline|main|polyfills|styles|vendor)\.[a-z0-9]+\.bundle\.js) 
    secure: always 
    redirect_http_response_code: 301 
    static_files: dist/\1 
    upload: dist/.* 

# Routing for a prod styles.bundle.css to serve directly 
- url: /(styles\.[a-z0-9]+\.bundle\.css) 
    secure: always 
    redirect_http_response_code: 301 
    static_files: dist/\1 
    upload: dist/.* 

# Routing for typedoc, assets and favicon.ico to serve directly 
- url: /((?:assets|docs)/.*|favicon\.ico) 
    secure: always 
    redirect_http_response_code: 301 
    static_files: dist/\1 
    upload: dist/.* 

# Any other requests are routed to index.html for angular to handle so we don't need hash URLs 
- url: /.* 
    secure: always 
    redirect_http_response_code: 301 
    static_files: dist/index.html 
    upload: dist/index\.html 
    http_headers: 
    Strict-Transport-Security: max-age=31536000; includeSubDomains 
    X-Frame-Options: DENY 

尋找任何反饋,我怎麼能做到這一點更好。

+0

我試過了,但是我的文件沒有上傳 –

+0

對不起,我沒有再使用Angular或Google雲端平臺,所以我不確定發生了什麼問題。兩條建議:確認您在上傳之前構建dist文件('ng build --prod && gcloud app deploy')並嘗試刪除'skip_files:'部分,以便上傳所有內容。 – Rob

相關問題