Universal: Enable Angular Universal with a Spring Boot backend

Created on 28 Nov 2016  路  4Comments  路  Source: angular/universal

Hi!
I'm submitting a feature request to get angular universal working with spring boot

I've been playing with Spring Boot and Nashorn to render javascript views which works great.
Now I would like to get NG2 working with Nashorn.

I've could help out with implementing it but I need some guidance.

To render .ejs files with nashorn you create a spring bean as follows

@Bean
public ScriptTemplateConfigurer reactConfigurer() {
    ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
    configurer.setEngineName("nashorn");
    configurer.setScripts(
        "templates/polyfill.js",
        "templates/ejs.min.js",
        "templates/render.js"
    );
    configurer.setRenderFunction("render");
    configurer.setSharedEngine(false);
    return configurer;
}

// polyfill.js

var window = this;
var global = this;
var console = {};
console.debug = print;
console.warn = print;
console.log = print;
console.error = print;

// render.js

// Create a real JSON object from the model Map

function toJsonObject(model) {
  var o = {};
  for (var k in model) {
    // Convert Iterable like List to real JSON array
    if (model[k] instanceof Java.type("java.lang.Iterable")) {
      o[k] = Java.from(model[k]);
    }
    else {
      o[k] = model[k];
    }
  }
  return o;
}

function render(template, model) {
  return ejs.render(template, toJsonObject(model));
}

Have any of you done any tests with nashorn?
Could you point me in the right direction to get started?

help wanted Needs Design

Most helpful comment

Hi @leon! How are you? Could you have a good solution/prototype for a ng+springboot project?
Thanks in advance.
Nico

All 4 comments

Perhaps the discussion in #280 would be a better place to reach out for some guidance.

Hi @leon! How are you? Could you have a good solution/prototype for a ng+springboot project?
Thanks in advance.
Nico

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings