๐ Rust server side rendering
The project aims to enable server side rendering on rust servers in the simplest and lightest way possible.
It use an embedded version of the v8 javascript engine (rusty_v8) to parse and evaluate a built bundle file and return a string with the rendered html.
Currently it works with Webpack bundler v5.65.0.
Getting started
Add this to your Cargo.toml:
[]
= "0.3.0"
Example
To render to string a bundled react project the application should perform the following calls.
use Ssr;
use read_to_string;
There are included examples with the most famous server frameworks and a default frontend react app made using npx create-react-app and the typescript --template flag. Check here the example ReactJS template.
Example with initial props
use Ssr;
use read_to_string;
Example with actix-web
Examples with different web frameworks are available in the examples folder.
Even though the V8 engine allows accessing the same isolate from different threads that is forbidden by this crate for two reasons:
- rusty_v8 library have not implemented yet the V8 Locker API. Accessing Ssr struct from a different thread will make the V8 engine to panic.
- Rendering HTML does not need shared state across threads.
For this reason parallel computation is a better choice. Following actix-web setup:
use ;
use RefCell;
use read_to_string;
use Ssr;
thread_local!
async
async
Contributing
Any helps or suggestions will be appreciated.
License
This project is licensed under the MIT License - see the LICENSE_MIT || LICENSE_APACHE file for more information.