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?