[英]Deployment to GCP App Engine, but not serving Server Side Rendered pages
I am trying to deploy an Angular 7 Universal application to Google Cloud Platform, App Engine.我正在尝试将 Angular 7 通用应用程序部署到 Google Cloud Platform、App Engine。 Deployment is successful, but it seems there is no Server Side Rendering happening, only client side.部署成功,但似乎没有服务器端渲染发生,只有客户端。
Building, and running a server work fine locally.在本地构建和运行服务器工作正常。 When I request the page in the browser, I can see Express / Angular rendering page on the local server, tag and all other content is served directly.当我在浏览器中请求页面时,我可以在本地服务器上看到 Express/Angular 渲染页面,标签和所有其他内容都是直接提供的。
When I deploy to the server and request the page, I only see a minimal html returned ( <app-root></app-root>
) which shows me there is no SSR happening.当我部署到服务器并请求页面时,我只看到返回的最小 html ( <app-root></app-root>
),这表明没有发生 SSR。 Application otherwise works well.应用程序否则运行良好。
My folder structure looks like this:我的文件夹结构如下所示:
dist/
- browser/
- index.html
- other js / css / assets
- server/
- main.js
- server.js
package.json包.json
"scripts": {
...
"start": "node dist/server.js",
app.yaml应用程序.yaml
runtime: nodejs10
handlers:
# Routing for bundles to serve directly
- url: /((?:runtime|main|polyfills|styles|vendor)\.[a-z0-9]+\.js)
#secure: always
redirect_http_response_code: 301
static_files: dist/browser/\1
upload: dist/browser/.*
# Routing for bundle maps to serve directly
- url: /((?:runtime|main|polyfills|styles|vendor)\.[a-z0-9]+\.js\.map)
#secure: always
redirect_http_response_code: 301
static_files: dist/browser/\1
upload: dist/browser/.*
# 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/browser/\1
upload: dist/browser/.*
# 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/browser/\1
upload: dist/browser/.*
# 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/browser/index.html
upload: dist/browser/index\.html
http_headers:
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: DENY
- url: /
static_dir: dist/
If it helps, here is a screenshot of Debug View of current files uploaded to GCP.如果有帮助,这里是上传到 GCP 的当前文件的调试视图的屏幕截图。
Where is this discrepancy between running the server happening?运行服务器之间的这种差异在哪里发生?
The approach you use it not for SSR.您使用它的方法不适用于 SSR。 Look at the app.yaml file, you describe how to serve the contents for each request URL.查看 app.yaml 文件,您描述了如何为每个请求 URL 提供内容。 For example, based on your app.yaml, if a browser request somefile.js
then app engine will just take that somefile.js
from dist/browser/somefile.js
and send to client.例如,根据您的app.yaml,如果浏览器请求somefile.js
然后应用程序引擎将只采取somefile.js
从dist/browser/somefile.js
,发送给客户端。 Therefore with these handlers rule, you simply tell app-engine to send all static content from the bucket to browser, then browser run all js files as normal and display the content on browser side.因此,使用这些处理程序规则,您只需告诉 app-engine 将所有静态内容从存储桶发送到浏览器,然后浏览器正常运行所有 js 文件并在浏览器端显示内容。 If you want SSR you must deploy something like an express app, Spring jsp app, etc. where the the app you build handle the content for each endpoint you specify in routing rules, not app-engine serve static content like this.如果您想要 SSR,您必须部署类似 express 应用程序、Spring jsp 应用程序等的应用程序,其中您构建的应用程序处理您在路由规则中指定的每个端点的内容,而不是 app-engine 提供像这样的静态内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.