我目前正在使用Angular-CLI生成的Angular4来创建项目结构,并且我能够使用ng-serve和开发和查看更改。现在,我想使用Google App Engine和WebApp2将其移至我自己的后端托管,并使用dev_appserver.py app.yaml运行它。目前,我可以使它工作的唯一方法是进行NG构建并将文件从DIST文件夹中提供服务。我想做到这一点,这样我就可以轻松地进行更改,但不必等待它每次重建。
您可以在Angular上使用Enviroment,以指向您的Python Rest服务,而另一种环境是生产的环境。
示例:
enviroment.ts
导出const环境= { 生产:错误, urlservices:'http://190.52.112.41:8075'};
enviroment.prod.ts
导出const环境= { 生产:是的, URLServices:'http://localhost:8080'};
以这种方式,您无需编译即可测试您的aplication,因为Angular总是会指向您Python App。
使用标准应用引擎配置:
的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
寻找有关如何更好地做到这一点的任何反馈。