Running jsdom in Nashorn

爷,独闯天下 提交于 2019-12-21 21:43:27

问题


I want to render d3 charts on the server. I had 3 options: Node, Phantom, and Nashorn.

I prefer Nashorn because my API is Scala Play and I don't want to manage another process. (deployment, load, queue, etc etc)

So now I need to get JSDom working in Nashorn, so that D3 will have something to render to.

This works so far but I can't figure out how to add jsdom

class Application @Inject() (val messagesApi: MessagesApi) extends api.ApiController {

  def test = ApiAction { implicit request =>
    ok("The API is ready")
  }

  def pptx = Action { implicit request =>
    val manager: ScriptEngineManager = new ScriptEngineManager
    val engine: ScriptEngine = manager.getEngineByName("nashorn")
    engine.eval(new FileReader(Play.getFile("/ext/lodash.js")))
    val output = engine.eval("function hello(){return _.join('Hello world nashorn does this thing'.split(' '), '-');} hello();")
    Ok(output.toString)
  }
}


回答1:


I'm loading a fork of domino in nashorn to run d3. Domino is a server-side DOM implementation based on Mozilla's dom.js. I loaded it using r.js from require.js. You can use this readfully function that is missing from nashorn to get require.js working.



来源:https://stackoverflow.com/questions/37425346/running-jsdom-in-nashorn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!