Closed BitFlipp3r closed 3 years ago
@BitFlipp3r Had some issues with SSR initially, but now its a little stable, will give it another try.
I dont fully understand SSR or have seen a complete example where there are alot of client side dependencies in an application like this one. How easy SSRS. Help appreciated.
Hey @asadsahi, any progress on the SSR?
Still quite complex, no idea. Help welcome. :)
@patrickgoeler @BitFlipp3r I have made some SSR progress in netcore2 branch of this project. But there are few libraries that aren't supported for SSR yet, e.g ng-bootstrap and material2 etc. So thought of updating you guys that those features are coming.
Awesome. Thank you very much for your efforts. Please take your time :)
Hi guys, just to update you on this one. I still can't see a clean way to make it work with SSR. With more features and libraries it breaks on SSR mode. So it is a trade off between having more functionality with 3rd party libraries or getting SSR working in a small demo project. So we'll have to wait until it gets more stability around third party libraries like ng-bootstrap or SignalR etc.
@asadsahi I am intrigued by this project as I contribute to a similar project here. I see that you have gotten some basic SSR and SEO concepts to work. Have you had any issues with bundling size or performance issues when doing SSR in production configs?
hi @isaac2004, as of now, SSR work in few basic scenarios and it work in SSR branch of this project as well.
But, based on my personal experience it isn't as streamlined as it should be. e.g I come across this issues https://github.com/angular/universal/issues/877, for which I have to use --aot flag for SSR build to make it work but the issue is still unanswered. Long discussion for same issue is here. Also, deployment of SSR isn't quick/ideal because of node_modules need to be packaged as part of deployment as explained in this issue.
I would love for npm to move to a package store like Dot Net Core has. I know it isn't as easy as that, but the need to have node_modules on the server or to bundle and deploy.
@isaac2004 why do you need node_modules on the server? just curious
For SSR to work 😊
good to know!
SSR is necessary for SEO optimization (for example, for the correct indexing of your site by search engines)
Fyi, when I enabled SSR, I have seen a few issues:
package.json
npm script build:ssr
. I had to change this to "build:ssr": "ng build --prod --project=ssr"
, as it seems that "build:ssr": "npm run build --project=ssr"
is just executing ng build --prod
and the --project=ssr
parameter doesn't seem to get added onto this command.
I seem to have to change Startup.cs
options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.bundle.js";
to options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.js";
in order to get this to work.
Even after making these changes, when the project is debugged, I receive NodeInvocationException: Http failure response for (unknown url): 0 Unknown Error
.
Finally I have managed to run SSR by angular cli 7 and material2. Here is the demo app using ASP.Net Core 2.2+Angular 7+Material2: Link
Greate @rezabayesteh can you please share your code.
Fyi, when I enabled SSR, I have seen a few issues:
package.json
npm scriptbuild:ssr
. I had to change this to"build:ssr": "ng build --prod --project=ssr"
, as it seems that"build:ssr": "npm run build --project=ssr"
is just executingng build --prod
and the--project=ssr
parameter doesn't seem to get added onto this command.- I seem to have to change
Startup.cs
options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.bundle.js";
tooptions.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.js";
in order to get this to work.- Even after making these changes, when the project is debugged, I receive
NodeInvocationException: Http failure response for (unknown url): 0 Unknown Error
.
I think because you running on local host and node did not accept self sign ssl. One way is add this line in to main.server.ts.
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
I was able to see html response after that. However css style not work and elements not show, still figuring out :(
Btw, this thing is pre-rendering only, not actual server site rendering. It is only able to pre-render index page at build time, other pages still render by client at run time so not really useful.
I think server side rendering in a complex angular app is challenging, especially when there are may external dependencies with SSR issues. and I have decided not to add SSR support in this repo. Hence closing this. Feel free to support in this area for another branch which might be useful for someone. Thanks
Hi @asadsahi Your template is really great, thanks for the hard work! The only thing missing would be SSR. Do you think it's possible to implement it like this? Kind Regards, Michael