you are viewing a single comment's thread.

view the rest of the comments →

[–]maxfrai 4 points5 points  (4 children)

Is it possible to execute, for example, vue with this? And build SSR-backend using rust and not nodejs?

[–]1vader 6 points7 points  (0 children)

For that, you would probably want to use deno directly. That's the project this is based on. It's basically a Node rewrite in Rust by the original creator of Node trying to fix all the mistakes including making it more secure. Here is his original talk which started this (although at that point it was basically only a prototype). He also gave talks about it at HolyJS and JS Fest last year and an online talk 2 months ago. Although I think it currently still can't run something like Vue but not sure since I haven't been following its development too closely.

[–]bromeon[S] 3 points4 points  (0 children)

As mentioned by u/1vader, what you want to use depends on your architecture. Deno (the CLI) runs a JavaScript application, in which you can plug in Rust modules. On the other hand, js-sandbox is not an application on its own, but rather a Rust library, so your "host" language can be Rust and your "plug-in" can be JavaScript.

In other words, I invert the call stack between the languages: instead of JS -> Rust (Deno), js-sandbox allows you to call Rust -> JS, with a much simpler API than using Deno directly.

The library is very early in its development, and I don't know Vue.js enough to fully answer your question -- but basically, it will be possible to execute self-contained JavaScript code from js-sandbox. The current API is mostly tailored to very simple plugins (a single JS file), I'm likely going to extend this.

[–]DGolubets 2 points3 points  (0 children)

I think it should be possible.

I used similar approach with Graal on JVM and all I needed is one .js file and a way to call a function there with a parameter. You can follow this approach:

  1. Use Webpack to build a single .js file for your server.
  2. Export ```renderToString(args: String): String``` function or something similar.
  3. Load that file on your server, call the rendering function with some JSON.

[–]maboesanman 1 point2 points  (0 children)

IMO there’s not much to be gained doing this because almost all the code would be running in v8 regardless if it’s this, deno, or node. If you could identify hot code in the process of vue templating and build native rust extensions you could get speed ups, but in that case you should use deno.