-
Notifications
You must be signed in to change notification settings - Fork 483
Enable Angular Universal with a Java backend #280
Comments
@jeffwhelpley thanks for starting this and your referral to the doc at https://docs.google.com/document/d/1a3LDFEi6xV9vNNZxjoRwIw-Z3pgj_HAZXCJe8-gkAeA/edit#. This is awesome. Given Spring has already gone GA supporting Script Based Templating on Nashorn, just wondering if compatibility with Spring is part of the plan? @sdeleuze at the Spring team does intend to support Angular 2 server side rendering as mentioned on SPR-13508 so it'd be good to see the two teams are joined up and collaborating on this front. Maybe we can invite Sébastien to discuss on the next meet up? |
@tbosch what do you think? |
Hey, indeed we would like to experiment with Spring support for Angular 2 server-side rendering as part of our Spring Framework 5 roadmap, and that would be awesome to be able to discuss that with you. You can find some information about our current support for isomorphic/universal applications here. Script loader extension to load JS and resource files from the classpath is also a key topic I would be interested to discuss with you. |
@jeffwhelpley last week I started POC'ing Universal on Spring. I basically wanted to write a renderer for Spring. Here is my repo for this POC: https://github.com/manekinekko/angular2-springboot-engine (BTW, I am not a Java guy so the code may seem messy or not well designed ^^) Here is the issue I opened for SystemJS: systemjs/systemjs#1113 @sdeleuze I tried to contact one of your french colleagues at Pivotal, I met at DevFest Paris this year (Brian Clozel) without any success :) |
@manekinekko Thanks for your feedback and experiment. I will have a look shortly. |
@sdeleuze I suspected Brian was on vacation ^^ |
Hey there, I'm very interested in this as well (using the latest Grails with Angular Universal). Has anyone made further progress with this? |
There are people working on this, but I have been out of it for a couple weeks getting ready for ng-conf. I will sync up with everyone next week and post a status here. |
Awesome thanks @jeffwhelpley |
@ryancampbell I will take you up on this! Let me get back in sync with Brad on this and will reach out to you within a week or so. |
I would be very interested by an update as well since we are close to begin active work on Spring Framework 5 where we would like to experiment and potentially provide support for Angular 2 running on Nashorn. |
@sdeleuze that'd be good. @jeffwhelpley sorry I started experimenting with Spring 4's Script Based Templating a couple of months ago but haven't gotten it to work yet, and then have been occupied with multiple family events. It'd be good to indeed have us all get synced up somehow. |
@sdeleuze check this my repo. We are having issues with the module loader, see more details here. |
@manekinekko Interesting, I guess we need to find the right polyfill to make it work ... |
I am in the process of pulling together all interested parties in the Java-Universal integration. There are a couple internal folks at Google in addition to all of you in the community that have posted here (and many more I talked to at ng-conf last week). This effort has been moving along somewhat slowly up to now, but it is time to make it legit. I think the first step will be a quick meeting of people who may be interested in contributing to this effort. If you want to simply get updates on the status, then watch this issue. If you want to be more heavily involved, email me at jeff at gethuman dot com. |
Also interested in doing this in house, so +1 |
j2v8 (https://github.com/eclipsesource/J2V8) just added support for linking (using jni) node.js into java applications - this may help reducing the amount of effort required for the port (instead of adapting nashorn) |
As the author of J2V8 I'll mention a few things. J2V8 is a set of Java bindings for V8. It exposes the V8 API to Java via JNI. Yesterday I finalized the support for node.js with J2V8. This means you start node itself (not just V8), execute scripts on node, and access the node message loop. You can also register Java methods to invoke when a JS Function is called, and you can call JS functions from Java. You can also get JS Objects and traverse them in Java. I haven't published binaries of the node integration yet, but I have the code to do that (I've built it on Linux and Mac, I'll try Windows next). |
@irbull could you paste a link to the repository? Excellent work! |
Nvm I see it above. |
Nice work! |
Only because I don't know Java, would you be willing to boilerplate this? |
I will try to make a small "hello angular-universal/j2v8" prototype and post here how it goes |
@bennylut that would be awesome. I am trying to get everyone together interested in this topic, but it looks like a lot of the Googlers won't be available until after Google I/O which is next week. So, I will get something on the calendar for the following week and in the meantime try to document the integration spec. |
@bennylut @irbull The J2V8 is amazing. This looks really similar to handlebars.java in that we can run the JS inside Java. Also nice is the callback. Wow. I wrote a Angular2 based front end served by a Spring 4 back end with mock data a few months ago. Will try out J2V8 to see how it goes by having it rendered on the back end instead. BTW I happen to notice the POM artifacts doesn't have the Linux version listed. @sdeleuze does this mean we need to have a J2V8ViewResolver for Spring 5? |
@bennylut sounds great. We'll have the Spring I/O conference next week in Barcelona, would be nice to show some initial work on that direction. |
@bennylut Currently I guess the answer is yes, but ideally what I would prefer is using J2V8 through JSR 223 that we support natively. As you can see in ScriptTemplateView, we use In any case, I think both Nashorn (that is now quite good in latest Java 8 builds, and continue to evolve as part of upcoming Java 9 release to support ES6) and J2V8 are interesting to support. Usually with Nashorn, the trick is to load a small polyfil before the JS library to create (like this one for React) some JS global variables. |
@sdeleuze I don't see why one will have a problem writing JSR223 compatibility layer for J2V8. Here are my two cents about Nashorn: Nashorn is a great project, it is much faster than rhino - still not close to v8 though. But even if you don't mind the performance differences on your server side - using it can cause major headache since for each change in angular-universal or one of its dependencies one will have to test and make sure that both nashorn and its polyfills are compatible with the changes and make the proper fixes if not. |
@vikerman Let me know if I can help! |
@niconavent @petercn Sorry for not answering to your comments, there was just too much study/work things going on + I was ill and was unable to find time to polish my example. But now I am able to provide a runnable version that is based on Angular 4, uses AOT and @angular/platform-server for rendering (Due the configuration I had to drop Angular CLI and use Webpack). You can find the project here: https://github.com/swaechter/spring-boot-angular-renderer I plan to invest more time in the future, because I would like to use Java SSR in production and at work (Spring Boot backends, but other frameworks are of course also possible). Maybe I can also team up with @vikerman? The next steps are to fix J2V8 problems on Windows*, add preboot.js for capturing user events, add HTTP handling and live reloading. So I am really open for feedback (Create an issue or write a mail). *For my daily work I use Linux and J2V8 works really well on Linux. It also works on Windows but I run into some strange DLL loading issues which I have to investigate in the next days |
@swaechter - Will take a look at your project. I was going to run Node.JS as a separate process. Will check out the J2V8 bridge solution as well. Using a binary installation of J2V8 might be problematic in certain situations. I think we should be able abstract out the communication channel between Java and Node.JS and people can choose what works for them - In-process with J2V8 or out of process IPC. Does that sound like a good idea? |
@vikerman there is just one considerations: if I go for IPC with node, I also could start a web server running on node, running Angular Universal on the node server and then go for a http proxy solution. Either way, I think it's a good idea to offer both J2V8 (or Nashorn) and IPC |
@vikerman Is any initial solution available for this yet? |
Anyone have any updates on this issue? |
@petercn I published my repository as Maven library (See here https://mvnrepository.com/artifact/ch.swaechter/angularj-ssr). I plan to rename the project to angularj-universal and split it up into several modules including an example + documentation. I would also like to integrate angular-ssr to use preboot.js. Keep in mind: My J2V8 solution based on the work of @bennylut (I owe you a beer) is only one possible implementation. If wished I can add other implementations like a solution that uses an IPC mechanism to communicate with a local NodeJS instance ( @vikerman Were you able to implement an IPC mechanism?) |
Sorry: I forgot to push my code to Github. Will do that now |
@swaechter Thanks for the excellent and prompt reply :-) |
@petercn Everything is ready now (Drop a mail if you encounter any problems):
I will invest more time in the next weeks (Finally (!) semester holidays). Although I got 10 and your followup question 7 likes, I don't really know what people/Java developer are expecting or looking/waiting for. So in case you liked these comments or are a Java developer:
What I am planing to do:
There was also a separate thread going on, but I guess we can discuss that now here (Link #721). |
This is great progress, just few things which would help for spring developers
|
@swaechter For the most part I'm simply looking for an angular SSR solution which can run on a JVM rather than needing a NodeJS instance. I'll definitely take your code for a spin and I totally agree with your roadmap, especially including preboot :-) Thanks again for your efforts and hopefully Angular / Angular CLI Team will take notice and begin to officially support Java back ends. The CLI team recently added this great documentation for the Node-based setup at least: https://github.com/angular/angular-cli/wiki/stories-universal-rendering |
@petercn In the last few weeks I played around with several projects. You can divide them into two groups: 1.) Projects that provide CommonJS module loading and [re]implement the Node.js API:
2.) Projects that only provide CommonJS module loading directly or via shim/polyfill/third party (But no implementation of the Node.js API):
As you see, all Node.js re-implementations are more or less dead (I guess this is due the development speed & impact of Node.js as a project/product) and all active JavaScript-only projects lack the Node.js API. Personally I don't think a Java JVM/Non Node.js/V8 based solution is possible at the moment because the Node.js implementation of Angular Universal uses modules like util, stream, events, fs and timers. If it's possible to rewrite Angular Universal without using Node.js modules (Pure JavaScript), it would be possible to use Angular Universal in Nashorn or RhingoJS (That would be really awesome). |
@swaechter Thanks for that detailed feedback of your findings |
@petercn No problem. The integrated platform-server (https://github.com/angular/angular/tree/master/packages/platform-server) itself doesn't rely on Node.js (or I missed it), but it's third party libraries like parse5 (src/parse5_adapter.ts) and zone.js/dist/zone-node.js require Node.js. Maybe @gdi2290 and @MarkPieszak can shed some light on this if it's theoretical possible to use JS-only libraries or what their thoughts were (Would be interesting for me) :) |
What about https://github.com/apigee/trireme ? |
Hi, any updates on this thread? |
Hello there, any news ? |
@bfwg @jobehi I haven't forgotten you :) There are several technical limitations at the moment that make it really hard to find a good and clean solution that is suitable for all environments. This was also the reason why I didn't want to release some half-working solutions. I created a feature/discussion issue in the official Angular repo: angular/angular#22443 |
@ronaldjeremy I also played around with Trireme but had some out of stack/memory problems due the JavaScript optimization (I can't remember exactly). But the bigger problem is this one from the README.md:
You can find the release dates here: https://nodejs.org/en/download/releases/ |
Closed in favour of #1000 |
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. |
There are a couple potential ways to do this through Nashorn. Opening this issue to start the discussion and plan out how we can achieve this goal.
The text was updated successfully, but these errors were encountered: