部署 Angular 6 通用到 GCP App Engine
deploying Angular 6 Universal to GCP App Engine
我正在寻找一个使用 Angular 6 Universal 并成功部署到 GCP App Engine 的示例项目。我搜索了 GitHub 但找不到示例——Universal Starter 不包括部署。另外,我的旧 Angular 5 通用配置不适用于这个新的 V6 项目。
当前错误来自 nginx:“502 Bad Gateway”
似乎是 favicon.ico 文件导致了问题——看起来像是 Node.js 问题。我刚刚在一个纯 Node.js 项目(不是 Angular)上处理了这个问题并且能够解决它,但是我在 Angular 上下文中找不到正确的配置。
server.ts
app.use(favicon('src/favicon.ico'));
angular.json(开头)
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"appname": {
"root": "",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/browser",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
{
"glob": "favicon.ico",
"input": "src",
"output": "/"
},
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets"
}
],
"styles": [
{
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
},
"src/styles.css"
], ...
dispatch.yaml(因为我有多个服务使用同一个域)
dispatch:
# Default service serves the typical web resources and all static resources.
- url: "*/favicon.ico"
service: default
问题是 package.json 中没有正确启动 Node。脚本中的这一行解决了问题...
"scripts": {
...
"start": "node dist/server.js",
我正在寻找一个使用 Angular 6 Universal 并成功部署到 GCP App Engine 的示例项目。我搜索了 GitHub 但找不到示例——Universal Starter 不包括部署。另外,我的旧 Angular 5 通用配置不适用于这个新的 V6 项目。
当前错误来自 nginx:“502 Bad Gateway” 似乎是 favicon.ico 文件导致了问题——看起来像是 Node.js 问题。我刚刚在一个纯 Node.js 项目(不是 Angular)上处理了这个问题并且能够解决它,但是我在 Angular 上下文中找不到正确的配置。
server.ts
app.use(favicon('src/favicon.ico'));
angular.json(开头)
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"appname": {
"root": "",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/browser",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
{
"glob": "favicon.ico",
"input": "src",
"output": "/"
},
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets"
}
],
"styles": [
{
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
},
"src/styles.css"
], ...
dispatch.yaml(因为我有多个服务使用同一个域)
dispatch:
# Default service serves the typical web resources and all static resources.
- url: "*/favicon.ico"
service: default
问题是 package.json 中没有正确启动 Node。脚本中的这一行解决了问题...
"scripts": {
...
"start": "node dist/server.js",