首页 > 解决方案 > Angular 通用 SSR 在 localhost 上工作但在 netlify 上不工作

问题描述

我正在尝试使用它来学习 Angular Universal,nestjs它似乎在我的 localhost 端口 4000 上运行良好,但是当在 Netlify 上进行构建时,我可以看到该站点正在运行,但 Angular Universal 无法运行。

npm run serve:ssr在本地主机中使用来运行项目。而在 netlify 中,我已经配置了构建和部署设置,如下图所示。

Netlify 构建和部署设置

我的直播网站点击这里

package.json

  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "dev:ssr": "ng run bharatas:serve-ssr",
    "serve:ssr": "node dist/bharatas/server/main.js",
    "build:ssr": "ng build --prod && ng run bharatas:server:production",
    "prerender": "ng run bharatas:prerender",
    "prebuild:ssr": "ngcc"
  },

server/app.module.ts

import { Module } from '@nestjs/common';
import { AngularUniversalModule } from '@nestjs/ng-universal';
import { join } from 'path';
import { AppServerModule } from '../src/main.server';

@Module({
  imports: [
    AngularUniversalModule.forRoot({
      bootstrap: AppServerModule,
      viewsPath: join(process.cwd(), 'dist/bharatas/browser')
    })
  ]
})
export class AppModule {}

server.ts

import 'zone.js/dist/zone-node';
import './server/main';
export * from './src/main.server';

你能帮我做错什么吗?为什么在查看源代码时看不到内容?为什么它只在我的 localhost:4000 上工作

标签: angularserver-side-renderingangular-universal

解决方案


推荐阅读