6

I am starting a new Angular website and thought I would start with the new .NET 5 but I am running into a few problems with adding SSR.

I created a new website and added an Angular client using ng new client-app then added the SSR using ng add @nguniversal/express-engine --client-project=client-app

I can run the Angular app using a power shell by executing npm run dev:ssr and everything works but when I tried to update my Startup.cs to use SSR by changing the script run by UseAngularCliServer from start to dev:ssr it builds and starts but in the browser there are errors:

:50740/browser-sync/socket.io/?EIO=3&transport=polling&t=NPHWxVs:1 Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR

zone-evergreen.js:2845 GET https://localhost:50740/browser-sync/socket.io/?EIO=3&transport=polling&t=NPHX5az net::ERR_SSL_PROTOCOL_ERROR

I assume these are because the server is using http not https

If I leave the startup pointing at start everything works but I don't get the SSR engine and I am confused how to start it now that the UseSpaPrerendering package is obsolete and no longer included.

How do I start the SSR Node server and configure it to use https?

How should this be setup so my development environment is as close to my production as possible?

Update


I have been reading through the documents and I believe I understand what is going on, first off the reason for the ERR_SSL_PROTOCOL_ERROR is due to the fact that socket.io is hard coded to use http but it looks like it reuses the base url (that includes the https when using SSL in the website) so this is simply copied over but the AngularCliServer only works in http. If you look into the source there is a comment

// Everything we proxy is hardcoded to target http://localhost because:
// - the requests are always from the local machine (we're not accepting remote
//   requests that go directly to the Angular CLI middleware server)
// - given that, there's no reason to use https, and we couldn't even if we
//   wanted to, because in general the Angular CLI server has no certificate

Bottom line if you wish to debug using prerender you are forced to turn off the SSL for the project.

Second the main problem is due to NodeServices being depreciated and no longer maintained by the .NET Core team. Looks like there is lots of complaints about dropping the support and Microsoft states that it needs to be a publicly maintained project and they have no interest in maintaining it. In short there is no longer any way to start the Node server using built in functionality.

Blazor does have a library JsInterop that executes JavaScript code, maybe this could be a possible answer using the <component /> tag helper or something similar?

Andy Braham
  • 7,763
  • 4
  • 38
  • 44
  • Have you found a solution because I'm about to die... – vslzl Feb 18 '21 at 12:13
  • @vslzl No, I haven't, looks like MS has put the development requirements onto the library developers to implement the support so until Angular/React decides to add the support we are stuck unless you write your own extension. I have a feeling it's due to MS concentrating on other technologies of their own. – Andy Braham Feb 19 '21 at 07:48
  • @AndyBraham have you tried loading data inside that blazor component? – Shervin Ivari May 08 '21 at 03:41
  • @ShervinIvari Yes that was one of my first thoughts, the problem is node, when I tried this approach there were several issues. Doesn't seem like node plays very nicely with SSR and https since the node server doesn't run https – Andy Braham May 10 '21 at 16:53
  • 1
    @AndyBraham I just wonder whats way, Its important thing Microsoft really should have something for it, at least some documentation:) – Shervin Ivari May 10 '21 at 17:11
  • So, no SSR support for Angular in ASP.NET for now? – Budda May 17 '21 at 13:41
  • @Budda That's what I gather, I can't find any direction on how this should be implemented in production, only in development. I am not sure if there is implementation in the works from Angular or .NET but as of right now yes. – Andy Braham May 20 '21 at 06:38
  • Actually, I think I overreacted: OP speaks about https on the local machine. For my current needs just HTTP is enough. And when I really need to make it HTTPS... I hope MS will make it supported till that time? Or, maybe there will be other alternatives. – Budda May 20 '21 at 16:50

0 Answers0