Integrating angular2 Universal with angular CLI project
-
OS - Windows 8
-
Versions - angular-cli: 1.0.0-beta.5 node: 4.3.1 os: win32 x64
-
Yes, the app was created using CLI
-
Steps - A. Created the app using following command -
ng new testAppB. Installed angular2-universal dependencies as mentioned in -
Angular 2 Universal quickstartC. Deployed client using command -
ng server(server started on port 4200) Started express server through -node server.js(server started on port 3000)D. Accessed the client and got following message in browser - test-app works! But when accessing
http://localhost:3000it gives below error message in console -
EXCEPTION: Error: Protocol "d:" not supported. Expected "http:".
STACKTRACE:
Error: Protocol "d:" not supported. Expected "http:".
at new ClientRequest (_http_client.js:52:11)
at Object.exports.request (http.js:31:10)
at Object.exports.get (http.js:35:21)
at D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\angular2-universal\dist\node\platform\node_xhr_impl.js:53:22
at ZoneDelegate.invoke (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\zone.js\dist\zone-node.js:281:29)
at Object.NgZoneImpl.inner.inner.fork.onInvoke (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\@angular\core\src\zone\ng_zone_impl.js:45:41)
at ZoneDelegate.invoke (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\zone.js\dist\zone-node.js:280:35)
at Zone.run (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\zone.js\dist\zone-node.js:174:44)
at NgZoneImpl.runInner (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\@angular\core\src\zone\ng_zone_impl.js:76:71)
at NgZone.run (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\@angular\core\src\zone\ng_zone.js:223:66)
D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\@angular\core\src\application_ref.js:302
throw e;
^
Kindly suggest if i had missed any step.
Any help will be appeciated.
@devCrossNet I see. Thanks for clarifying.
Looks like PR https://github.com/angular/angular-cli/pull/5194 is where we are at. Seems like that one is necessary to get the rest of it working. Appears to have been some commit activity five days ago. Of course @FrozenPandaz is the best person to comment on all those though.
Looks like #5194 has been merged into master a few hours ago. Where does this leave us?
Leaves us waiting for a release now :)
I think we need https://github.com/angular/angular-cli/pull/5547 too. Somebody should rebase to fix the conflict and write unit test to approve it.
According to @FrozenPandaz it does not depend on #5547. Where do we go from here?
Yes, the other PR (#5194) does not depend on #5547. So now the server bootstrap code is replaced as well.
But the feature what we want to have (interating universal into angular cli) needs #5547 to build the correct bundle for NodeJS.
@kondi Gotcha, thanks!
is this coming soon?
Who owns this? Any update?
UP! It would be really nice to be able to make pre-rendered apps without giving up on the CLI. The CLI is very useful for development.
To wait you can style clone this project : https://github.com/designcourse/angular-seo. Hope I'm saving some lives lol
@glemiere unfortunately, if I add a lazy module into that, it doesn't get rendered server side.
ERROR { Error: Uncaught (in promise): ReferenceError: System is not defined
ReferenceError: System is not defined
Also, I can't figure out how to access cookies server side. Went back and forth between different examples found across GitHub, but they're very different from the example in your link, I can't make anything out of them (plus, most are using a unversal-starter).
Have you managed to make it work with lazy modules or read cookies server side?
angular2-cookie has a working implementation for server side. It involves having a separate provider for node and using Zone.current
On Sun 18 Jun, 2017, 6:44 PM Marian Stoica, [email protected] wrote:
@glemiere https://github.com/glemiere unfortunately, if I add a lazy module into that https://github.com/designcourse/angular-seo, it doesn't get rendered server side.
ERROR { Error: Uncaught (in promise): ReferenceError: System is not defined ReferenceError: System is not defined
Also, I can't figure out how to access cookies server side. Went back and forth between different examples found across GitHub, but they're very different from the example in your link, I can't make anything out of them.
Have you managed to make it work with lazy modules or read cookies server side?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/1050#issuecomment-309277059, or mute the thread https://github.com/notifications/unsubscribe-auth/AAeZ8SGRnnTAQu7Q05WLCVIsW-I5enBDks5sFSLNgaJpZM4Ixuiz .
@glemiere I have the same issue as @MrCroft. Is there any solution for lazy loaded modules rendering?
When this feature will be supported?
@Brocco At large scale angular site is taking 30 seconds for first meaningful paint on slower network. Could you please give us a time line for SSR. I don't want to switch from CLI.
Guys, any news? This feature is really important @MarkPieszak
@glebmachine as far as I know, there's 1x PR left and it has a very small change before it can be merged: https://github.com/angular/angular-cli/pull/5547
Dear god, i hope it will be done soon!)
any good example right now, how to integrate server side rendering with angular cli?
P.S. I am quite disappointed in support of angular-cli team, it looks like noone cares about this issue
@dimitriy-k and anyone else looking, then the best example I have found for at server side rendered solution with angular cli is this article: https://coursetro.com/posts/code/68/Make-your-Angular-App-SEO-Friendly-(Angular-4-+-Universal)
The biggest issue though, is that the server code is only running through ngc and not webpack. Therefor all loaders (sass etc.) and environment variables are not passed to the server side code and will not work.