[英]How to deploy frontend and backend at the same time to App Engine?
目前,我有两个不同的包 - 一个带有我的 Java Web 应用程序(API 等)的 WAR 文件和一个 Angular 8 dist zip 文件。 我想要么部署到同一个应用引擎实例,要么部署到单独的应用引擎实例。
如何将它们都部署到同一个应用引擎实例并仍然集成它们?
将它们都部署到同一个实例是否是一种好习惯,还是应该将它们分开?
如果我将它们部署到单独的实例 - 我如何将它们指向另一个并避免 CORS 问题?
我不建议您将两者部署在同一个实例上。 为什么? 因为,如果你想更新你的前端,例如,更新一个 CSS 或一个类型问题,你必须为此重新部署你的完整应用程序。
顺便说一下,我建议您部署 2 个不同的实例。 前端名称实例的前面,以及默认后端实例的后面。
您必须自定义 app.yaml 文件。 对于前端,只提供静态文件,我使用这个文件
service: frontend
runtime: python37
handlers:
# Routing for bundles to serve directly
- url: /((?:(?:(?:inline|main|runtime|common|polyfills|styles|vendor)\.[a-z0-9]+\.js)|(?:[0-9]+\.[a-z0-9]+\.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]+\.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
expiration: 0s
http_headers:
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: DENY
/static 目录中仅提供静态资源。 没有实例产生,没有成本。
注意:它也是一个有角度的应用程序,我在文件中使用了 python 运行时。 没有影响,使用你想要的,它只是静态资源服务!
支持是标准的并且特定于您的应用程序。 如果您正确设置了处理程序,则不应出现 cors 问题。
如果不是这种情况,请告诉我,我们将检查您的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.