Skip to content

Commit

Permalink
doc: update crate documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerioageno committed Mar 9, 2024
1 parent e33cc2c commit f98369b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
[![API](https://docs.rs/ssr_rs/badge.svg)](https://docs.rs/ssr_rs)
[![codecov](https://codecov.io/gh/Valerioageno/ssr-rs/branch/main/graph/badge.svg?token=O0CZIZAR7X)](https://codecov.io/gh/Valerioageno/ssr-rs)

The project aims to enable server side rendering on rust servers in the simplest and lightest way possible.
The crate 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 (<a href="https://github.com/denoland/rusty_v8" target="_blank">rusty_v8</a>) to parse and evaluate a built bundle file and return a string with the rendered html.
It uses an embedded version of the [V8](https://v8.dev/) javascript engine (<a href="https://github.com/denoland/rusty_v8" target="_blank">rusty_v8</a>) to parse and evaluate a built bundle file and return a string with the rendered html.

Currently it works with latest [Vite](https://vitejs.dev/), latest [Webpack](https://webpack.js.org/) and [React 17](https://react.dev/) - Check the examples folder.

Expand Down Expand Up @@ -42,7 +42,21 @@ fn main() {
}
```

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 <a href="https://github.com/Valerioageno/ssr-rs/tree/main/client">here</a> the example ReactJS template.
## What is the "entryPoint"?

The `entryPoint` is the function that returns an object with one or more properties that are functions that when called return the rendered result.

In case the bundled JS is an IIFE the `entryPoint` is an empty string.

```javascript
// IIFE example | bundle.js -> See vite-react example
(() => ({ renderToStringFn: (props) => "<html></html>" }))() // The entryPoint is an empty string
```

```javascript
// Varible example | bundle.js -> See webpack-react example
var SSR = () => ({renderToStringFn: (props) => "<html></html>"}) // SSR is the entry point
```

## Example with initial props

Expand Down Expand Up @@ -80,7 +94,7 @@ Even though the V8 engine allows accessing the same `isolate` from different thr
1. 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.
2. Rendering HTML does not need shared state across threads.

For this reason parallel computation is a better choice. Following actix-web setup:
For the reasons above parallel computation is a better choice. Following actix-web setup:

```rust
use actix_web::{get, http::StatusCode, App, HttpResponse, HttpServer};
Expand Down Expand Up @@ -126,6 +140,13 @@ async fn index() -> HttpResponse {

Any helps or suggestions will be appreciated.

Known TODOs:
- Add examples with other rust backend frameworks
- Add examples with other frontend frameworks (i.e. vue, quik, solid, svelte)
- Add benchmark setup to test against Deno and Bun
- Explore support for V8 snapshots
- Explore js copilation to WASM (i.e. [javy](https://github.com/bytecodealliance/javy))

## License

This project is licensed under the MIT License - see the <a href="https://github.com/Valerioageno/ssr-rs/blob/main/LICENSE_MIT">LICENSE_MIT</a> || <a href="https://github.com/Valerioageno/ssr-rs/blob/main/LICENSE_APACHE">LICENSE_APACHE</a> file for more information.
Expand Down
23 changes: 17 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![doc(html_logo_url = "https://raw.githubusercontent.com/Valerioageno/ssr-rs/main/logo.png")]

//!
//! The project aims to enable server side rendering on rust servers in the simplest and lightest way possible.
//! The crate 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 (<a href="https://github.com/denoland/rusty_v8" target="_blank">rusty_v8</a>) to parse and evaluate a built bundle file and return a string with the rendered html.
//! It uses an embedded version of the [V8](https://v8.dev/) javascript engine (<a href="https://github.com/denoland/rusty_v8" target="_blank">rusty_v8</a>) to parse and evaluate a built bundle file and return a string with the rendered html.
//!
//! Currently it works with latest [Vite](https://vitejs.dev/), latest [Webpack](https://webpack.js.org/) and [React 17](https://react.dev/) - Check the examples folder.
//!
Expand All @@ -21,7 +21,6 @@
//! To render to string a bundled react project the application should perform the following
//! calls.
//!
//!
//! ```no_run
//! use ssr_rs::Ssr;
//! use std::fs::read_to_string;
Expand All @@ -38,9 +37,21 @@
//! assert_eq!(html, "<!doctype html><html>...</html>".to_string());
//! }
//! ```
//! Check how to use it with actix, rocket, warp and other frameworks <a href="https://github.com/Valerioageno/ssr-rs/tree/main/examples" target="_blank">here</a>.
//! ## What is the "entryPoint"?
//! The `entryPoint` is the function that returns an object with one or more properties that are functions that when called return the rendered result.
//! In case the bundled JS is an IIFE the `entryPoint` is an empty string.
//! ```javascript
//! // IIFE example | bundle.js -> See vite-react example
//! (() => ({ renderToStringFn: (props) => "<html></html>" }))() // The entryPoint is an empty string
//! ```
//! ```javascript
//! // Varible example | bundle.js -> See webpack-react example
//! var SSR = () => ({renderToStringFn: (props) => "<html></html>"}) // SSR is the entry point
//! ```
//!
//! # Example with initial props
//! # Example with initial props
//!
//! ```no_run
//! use ssr_rs::Ssr;
Expand Down Expand Up @@ -75,7 +86,7 @@
//! 1. 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.
//! 2. Rendering HTML does not need shared state across threads.
//!
//! For this reason parallel computation is a better choice. Following actix-web setup:
//! For the reasons above parallel computation is a better choice. Following actix-web setup:
//!
//! ```no_run
//! use actix_web::{get, http::StatusCode, App, HttpResponse, HttpServer};
Expand Down

0 comments on commit f98369b

Please sign in to comment.