在 Azure Devops 上部署 Angular Universal SSR + .NET Core

Lau*_*ine 6 server-side-rendering azure-devops asp.net-core angular-universal

我在 azure devops 上有一个带有 .net core 和 angular 的应用程序。现在,我想实现 Angular Universal SSR。

然后,我在我的项目上做了:

ng 添加@nguniversal/express-engine --clientProject angular.io-example

我的 package.json 是:

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "npm run build:client-and-server-bundles && npm run compile:server",
    "build:ssr": "npm run build:client-and-server-bundles && npm run compile:server",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "bundle-report": "ng build --extract-css --stats-json && webpack-bundle-analyzer dist/stats.json",
    "compile:server": "webpack --config webpack.server.config.js --progress --colors",
    "serve:ssr": "node dist/server",
    "build:client-and-server-bundles": "ng build --extract-css --prod && ng run Catevering:server:production"
  }
Run Code Online (Sandbox Code Playgroud)

然后,我可以在 kudu 上看到下一个结构文件:

  • 服务器
  • 浏览器
  • 服务器.js

[在这里检查我的文件结构][1]

最后,我更改了 startup.cs 文件的下一行:

services.AddSpaStaticFiles(configuration =>
{
    configuration.RootPath = "ClientApp/dist";
});
Run Code Online (Sandbox Code Playgroud)

经过:

services.AddSpaStaticFiles(configuration =>
{
     configuration.RootPath = "ClientApp/dist/browser";
});
Run Code Online (Sandbox Code Playgroud)

这种方式有效并且我的应用程序正在运行。但是,我的应用程序无法作为 SSR 运行。在我的本地主机中,我的应用程序作为 SSR 使用下一个命令:

节点服务器.js

为此,我尝试像这样更改我的代码:

services.AddSpaStaticFiles(configuration =>
{
     configuration.RootPath = "ClientApp/dist/server.js";
});
Run Code Online (Sandbox Code Playgroud)

但这是行不通的。但是,我的后端 web api 正在运行。

有人可以帮助我吗?

我需要在 azure devops 上以 SSR 的形式运行我的应用程序。