【发布时间】:2019-11-02 00:11:41
【问题描述】:
我正在尝试将 Angular 7 Universal 应用程序部署到 Google Cloud Platform App Engine。部署成功,但似乎没有发生服务器端渲染,只有客户端。
在本地构建和运行服务器可以正常工作。当我在浏览器中请求页面时,我可以在本地服务器上看到 Express / Angular 渲染页面,直接提供标记和所有其他内容。
当我部署到服务器并请求页面时,我只看到返回的最小 html (<app-root></app-root>),这表明我没有发生 SSR。否则应用程序运行良好。
我的文件夹结构如下:
dist/
- browser/
- index.html
- other js / css / assets
- server/
- main.js
- server.js
package.json
"scripts": {
...
"start": "node dist/server.js",
app.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/
如果有帮助,这里是上传到 GCP 的当前文件的调试视图的屏幕截图。
运行服务器之间的这种差异发生在哪里?
【问题讨论】:
标签: node.js angular google-cloud-platform angular-universal server-side-rendering