-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrating angular2 Universal with angular CLI project #1050
Comments
You wouldn't need to start the Client separately, if you're using Universal it'll be serving everything through the server only. You want to access port 3000 then. Express is serving the index (w/ the universal app). Give that a shot and let me know |
Hi @MarkPieszak, thanks for reverting. I started the application on port 3000 only as suggested and then accessed the URL, but getting the same error again. I am attaching the screenshot for reference. |
Try upgrading Node to 6+ or something, this might be some Express issue. It thinks you're trying to do You have:
|
Thanks for the inputs @MarkPieszak, I will try it after upgrading Node to latest version. The Express version that i am referring to is - |
@MarkPieszak, i had updated the node version to 6.2.1, however i am still getting the same error :( Please suggest if i am doing something wrong here. |
Yeah, the same error happening when you generate app via angular-cli and add server code from https://universal.angular.io/quickstart/ |
Hi @neilhem, any luck? |
no luck, on gitter chat of angular-universal I have written about error, so they told me that they will update code example as soon as possible |
@gdi2290 Not sure if this one was on your radar, can't tell if it's CLI or Universal itself |
I followed the example as well, but i have totally different errors coming from the server.ts file:
Did you guys had similar problems? BR |
Nevermind, got the same error as well. EXCEPTION: Error: Protocol "d:" not supported. Expected "http:" |
Yeah, the problem was that the typings command failed so I had to add the But I still get your error. BR On 11 June 2016 at 20:45, Vinod Bhargava notifications@github.com wrote:
Med vänlig hälsning | Met vriendelijke groet | Топли поздрави | Kind Regards Vasko Gjurovski Tel +38976361002 Bagdatska 15/7 | 1000 Skopje | Macedonia
Polar Cape is representing Sweden in the European Business Awards Please watch our video and vote http://www.businessawardseurope.com/ for http://www.businessawardseurope.com/ Polar Cape is one of the best places to work 2015 |
I did a little more research and I tried to follow this example: http://mean.expert/2016/06/04/angular-2-loopback-universal/ However, at the end I got the same error message: Error: Protocol "d:" not supported. Expected "http:" This is making me think that this might be a problem with a newer version of one of the dependencies, but I just cannot pinpoint which one. Main suspects preboot and angular2-universal. Still looking... BR |
I'll take a deeper look tomorrow and see if I have any luck integrating the CLI with it. Have you tried the Universal Starter? Also, Universal only works with router-deprecated at this moment, maybe it has something to do with that. |
I did try the Universal starter and it was working fine, but as the CLI is And, thanks for the help... :) BR On 11 June 2016 at 23:55, Mark Pieszak notifications@github.com wrote:
Med vänlig hälsning | Met vriendelijke groet | Топли поздрави | Kind Regards Vasko Gjurovski Tel +38976361002 Bagdatska 15/7 | 1000 Skopje | Macedonia
Polar Cape is representing Sweden in the European Business Awards Please watch our video and vote http://www.businessawardseurope.com/ for http://www.businessawardseurope.com/ Polar Cape is one of the best places to work 2015 |
FYI, I did try a stripped version of my app with the router-deprecated and EXCEPTION: Error: Protocol "d:" not supported. Expected "http:" So I do not think it is the router that makes the problem. BR On 12 June 2016 at 03:18, Vasko Gjurovski vasko.gjurovski@polarcape.com
Med vänlig hälsning | Met vriendelijke groet | Топли поздрави | Kind Regards Vasko Gjurovski Tel +38976361002 Bagdatska 15/7 | 1000 Skopje | Macedonia
Polar Cape is representing Sweden in the European Business Awards Please watch our video and vote http://www.businessawardseurope.com/ for http://www.businessawardseurope.com/ Polar Cape is one of the best places to work 2015 |
Ok I'll take a look, yeah we haven't upgraded it yet mainly because of the ever changing router states, of course for the newest one we will update it as quickly as we can! |
shouldn't angular CLI support universal from ground up? |
Unfortunately I don't think it could from the way it is now, because asp.net for example has an extremely different setup than a typical ng2 project. It would have to be an add-on to the CLI if they had it, since it would be very different itself. Steve Sanderson made a nice yeoman generator for asp.net core and angular2 (it's using Universal as well) if you want to take a look at it. http://blog.stevensanderson.com/2016/05/02/angular2-react-knockout-apps-on-aspnet-core/ |
thanks for the link. Is it possible/usable to combine this with angular CLI? |
I haven't tried, but I think you have to of first made an app with I would hope sometime in the future we can integrate a .NET add on for the CLI though |
I believe @Brocco was looking into Universal integration, but I don't know more than that. |
We are in the exploratory stages of integrating angular universal into the CLI to determine feasibility. Once that has been determined we will come up with a strategy to implement, which will be discussed either in this issue or another issue in this repo (or possibly on the universal repo). Thanks for your interested in incorporating universal in the CLI!!! |
I'd love to help Mike. I guess anything Node, express/Hapi/koa integration, wouldn't be too bad. Let me know how I can get involved! |
Is there a working-group & roadmap for cli/universal integration ? |
Some news or nothing ? |
@pdelorme @choucry13 |
@KhalipskiSiarhei you can try import it function from inline..bundle.js, that has been generated after ng build / ng build --prod. |
@PSTime I am not sure how it is possible to import inline.bundle in server ASP.NET Core environment: in Microsoft.AspNetCore.SpaServices.Prerendering.Prerenderer.RenderToString(...) it is possible to pass one module only, which in fact is main.bundle. Furthermore, inline.bundle is created for browser environment because it contains document.getElementsByTagName, document.createElement, window references which are not available in server environment. |
If it helps i have a small demo showing Universal working in the CLI with both |
@Toxicable thanks, I will look at it. For now we still use CLI for client bundles and webpack for server bundles and it is not ideal... |
@PSTime I can confirm that I also have not been able to import I suggest filing a separate bug on this @angular/cli repo.. Do you mind filing it? 💐 😌Be sure to reference the @nguniversal/module-map-ngfactory-loader instructions. |
@somombo what version of the CLI? you need v1.3+ for |
@Toxicable Thank you for this! Do you have any examples for things such as:
? |
@MrCroft as far as I know I don't think it will change too much from how it looks now. As for cookies I havn't looked at how this will work yet, I'll put that on my list though, if you want to make an issue/proposal on https://github.com/angular/universal for it that would be appreciated. Your second point is referring to a concept called StateTransfer, this is the process of storing your state on the server then transferring it to the client and reusing it. |
Is universal now part of angular client or not yet? If not, is there any timeline when it could be? |
@ennyta Yes, take a look at universal-starter to see it in action. I'll be updating the docs here in the CLI for it as well. @MrCroft You'll still have to run and bundle the server things yourself, it won't be part of ng serve, that will still produce only the client bundle. The concept of universal implies the server aspect, so there needs to be that separation. Also this gives freedom to any type of node server someone wishes to use, hapi koa express etc. As for cookies, in the server you'd have to handle it yourself by passing in the req object to the providers[] and then use Dependency injection to have the server use those, while the client gets them from document.cookies. Hope that helps a little bit! Also, right now you can manually create or use one of the TransferHttp examples we have, but soon it will be part of Core that will (optionally) handle it, if you tell it to do it for a certain GET call. |
Thanks @MarkPieszak |
@ennyta If you're using https://github.com/angular/universal-starter and in the |
@Toxicable , I am in client and have two folders following https://github.com/angular/angular-cli/wiki/stories-universal-rendering. |
@ennyta are you planning on doing prerendering or using Express/aspnetcore to do dynamic rendering? |
@Toxicable Trying to do prerendering, managed to run it and now getting error like this: Any idea if it is fixable? I see several people in this topic run into them, but I don't see if there is a solution for it. |
@ennyta the cli probably needs to include nodeExternals and whitelist angular modules that way webpack can read the es6 module syntax |
This seems to have been removed: https://github.com/Toxicable/universal-starter/tree/cli (I get a 404). @gdi2290 About prerendering, I've read that "it renders your application and replaces the dist index.html with a rendered version.". What is that useful for? I mean, we don't only have a root (home) page. Should we manually go over all the routes and generate a static html file for each possible route? And is this done by simply replacing the value of the EDIT: |
@ennyta See this issue for for information on that issue #7200 @MrCroft My demo has been merged into https://github.com/angular/universal-starter/tree/master/cli |
Since your comment, I've been searching back and forth for an actual example, but couldn't find one. So, I've blindly managed to do it after reading different issues/browsing through different repos, with this in my
While also providing a dummy It does work, but I have to ask: is this exactly what you had in mind? Am I doing it the right way?
|
Regarding #1050 (comment) by @gdi2290:
I have experienced the same issue when trying to use ng-bootstrap on with universal. Does anyone know if there is an open issue for the above (I can't seem to find one)? |
Can be closed since the CLI does work with Universal |
@MrCroft nicely done, yes that's a great way to get it! Yeah you're fine, you could also just do your own interface for it since you know the exact pieces you want. Either way is fine, since this is all in the server render anyway! 👍 |
@somombo Let me know if you found a way out of it! |
@itstyro I "fixed" my issue by basically not using ng-bootstrap i.e. forked their bit of code that i needed, and incorporated that directly into my project.. lol Yeah, apart from the node externals outlined above, I'm still finding a variety of problems with the way angular-cli builds the server aspect of the project. For example in my Also in the |
Closing as @Toxicable correctly mentioned CLI does work with Universal. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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 testApp
B. Installed angular2-universal dependencies as mentioned in -
Angular 2 Universal quickstart
C. 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:3000
it 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.
The text was updated successfully, but these errors were encountered: