🚀 Rust server side rendering

🚀 Rust server side rendering

🚀 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 v4.44.2; check it out here a full project who use this crate.

Getting started

Add this to your Cargo.toml:

[dependencies]
ssr_rs = "0.2.3"

Example

The all logic is stored inside the render_to_string() function.

use ssr_rs::Ssr;
use std::fs::read_to_string;

fn main() {

    let source = read_to_string("./path/to/build.js").unwrap();

    let html = Ssr::render_to_string(&source, "entryPoint", None);
    
    assert_eq!(html, "<!doctype html><html>...</html>".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_rs::Ssr;
use std::fs::read_to_string;

fn main() {

    let props = r##"{
        "params": [
            "hello",
            "ciao",
            "こんにちは" 
        ]
    }"##;

    let source = read_to_string("./path/to/build.js").unwrap();

    let html = Ssr::render_to_string(&source, "entryPoint", Some(&props));
    
    assert_eq!(html, "<!doctype html><html>...</html>".to_string());
}

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.


Information - Updated Jun 05, 2022

Stars: 16
Forks: 2
Issues: 1
Actix

7.2K

Actix Rust Framework for web and wasm based applications

Rust's premier framework for handling large scale web applications across a wide varaitey of operating systems

Actix Rust Framework for web and wasm based applications

Rust/Actix Example

REST server using the Rust language to give you an idea of how it all works

Rust/Actix Example

Example using Rust Actix-web (web framework) with juniper (Graphql) with diesel (ORM)

Diesel's Getting Started guide using SQLite for Actix web

Example using Rust Actix-web (web framework) with juniper (Graphql) with diesel (ORM)

Example microservice in Rust and Actix

Beginners guide to using rust with a simple example

Example microservice in Rust and Actix

OpenGliderNetwork client for Rust based on actix

MIT license (LICENSE-MIT or

OpenGliderNetwork client for Rust based on actix

A Rust webservice using Actix

Crate tables against your database

A Rust webservice using Actix

rust_actixweb_boilerplate

The Rust Actix_Web Boilerplate is a boilerplate for developers who want to get started with Actix_web's web applications faster

rust_actixweb_boilerplate

REST API with Rust using Actix-Web 2

GET /users ➡ returns all users

REST API with Rust using Actix-Web 2

REST API with Rust using Actix-Web 2

GET /users ➡ returns all users

REST API with Rust using Actix-Web 2

rust-actix-rest-api-boilerplate

A Rust RESTful API server with actix web and docker

rust-actix-rest-api-boilerplate

Rust actix json request example

Send a json request to actix, and parse it

Rust actix json request example
Facebook Instagram Twitter GitHub Dribbble
Privacy