简体   繁体   English

Google App Engine上的Angular4和WebApp2

[英]Angular4 and WebApp2 on google App engine

I am currently using a angular4 projected generated by angular-CLI to create the project structure and I was able to serve it using ng-serve and develop and see changes. 我目前正在使用由angular-CLI生成的angular4投影来创建项目结构,并且能够使用ng-serv为其提供服务并开发并查看更改。 Now I would like to move it to being hosted on my own backend, using google app engine and webApp2 and run it using dev_appserver.py app.yaml. 现在,我想将其移动到使用Google App Engine和webApp2托管在我自己的后端上,并使用dev_appserver.py app.yaml运行它。 Currently the only way I can get it to work is by doing an ng-build and serving the files out of the dist folder. 目前,使它起作用的唯一方法是执行ng-build并将文件从dist文件夹中提供。 I would like to make it so I can easily make changes but not have to wait for it to rebuild each time. 我想这样做,这样我就可以轻松进行更改,而不必每次都等待它重建。

You can use enviroment on angular in order to point you python rest service and another enviroment to production. 您可以在angular上使用环境,以便为您提供python rest服务和另一个生产环境。

Example: 例:

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'
};

In this way , you dont need to compile to test you aplication because angular always will be pointed to you python app. 这样,您就不需要编译来测试您的应用程序,因为angular始终会指向您的python应用程序。

An app.yaml solution using the standard App Engine config: 使用标准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

Looking for any feedback on how I could do this better. 寻找任何有关如何更好地做到这一点的反馈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM