6

I have an app on azure devops with .net core and angular. Now, I want to implement Angular Universal SSR.

Then, I did on my project:

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

My package.json is:

"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"
  }

Then, I can see on kudu the next structure files:

  • server
  • browser
  • server.js

[Check here my file structure][1]

Finally, I change the next line on my startup.cs file:

services.AddSpaStaticFiles(configuration =>
{
    configuration.RootPath = "ClientApp/dist";
});

By:

services.AddSpaStaticFiles(configuration =>
{
     configuration.RootPath = "ClientApp/dist/browser";
});

This way works on and my app is working. But, my app is not working as SSR. In my localhost my app works as SSR with the next command:

node server.js

For that, I tried to change my code like this:

services.AddSpaStaticFiles(configuration =>
{
     configuration.RootPath = "ClientApp/dist/server.js";
});

But this is not working. However, my backend web api is working.

Someone can help me?

I need to run my app as SSR on azure devops.

  • I'm facing the same issue. I have a project built on ASP.NET Core 3.1 with Angular 9. The production and SSR builds work fine except I don't know how to serve the server.js file in a .NET Core environment. Any help is much appreciated. – Nexus Apr 16 '20 at 10:45
  • Hi, I have also faced the same issue. Did you find any solution. Stuck from these past three days. Any help is much appreciated. – Karnan Muthukumar Sep 16 '20 at 09:17
  • @Nexus Did you found any solution. I have also the same project built on ASP.NET Core 3.1 with Angular 9. I need to know how to configure and publish this in azure – Karnan Muthukumar Sep 17 '20 at 11:49
  • 1
    @KarnanMuthukumar unfortunately not, haven't found useful resources on how to set up Angular + SSR on IIS. It was overkill for my project and too much time and effort were being wasted. I refactored the project to use MVC razor views for public pages and an Angular SPA for the admin dashboard. – Nexus Sep 18 '20 at 00:02

0 Answers0