Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Enable Angular Universal with a Spring Boot backend #631

Closed
leon opened this issue Nov 28, 2016 · 4 comments
Closed

Enable Angular Universal with a Spring Boot backend #631

leon opened this issue Nov 28, 2016 · 4 comments

Comments

@leon
Copy link

leon commented Nov 28, 2016

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?

@filoxo
Copy link

filoxo commented Nov 30, 2016

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

@MarkPieszak MarkPieszak changed the title Support for Spring Boot Enable Angular Universal with a Spring Boot backend Feb 1, 2017
@niconavent
Copy link

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

@CaerusKaru CaerusKaru added this to the Backlog milestone Mar 7, 2018
@Toxicable
Copy link

Closed in favour of #1000

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants