[][src]Struct ssr::Ssr

pub struct Ssr { /* fields omitted */ }

The main struct of the crate that manages Node.js process and handles rendering.

Implementations

impl Ssr[src]

pub async fn new(cfg: SsrConfig) -> Result<Self, InitializationError>[src]

Creates an Ssr instance.

Example

let ssr =
  Ssr::new(
    SsrConfig {
      port: 9000,
      js_worker: PathBuf::from("./node_modules/ssr-rs/worker.js"),
      global_js_renderer: Some(PathBuf::from("./js/ssr.js")),
    }
  );

pub async fn render<D: Serialize>(
    &self,
    uri: &Uri,
    data: &D,
    js_renderer: JsRenderer
) -> Result<String, RenderingError>
[src]

Renders a response to an incoming request using Node.js worker.

Example

let uri = req.uri();
let data = db::get_data();
match ssr.render(uri, &data, JsRenderer::Global).await {
    Ok(html) => HttpResponse::Ok().body(html),
    Err(error) => {
        error!("Error: {}", error);
        HttpResponse::InternalServerError().finish()
    }
}

Trait Implementations

impl Clone for Ssr[src]

Auto Trait Implementations

impl !RefUnwindSafe for Ssr[src]

impl Send for Ssr[src]

impl Sync for Ssr[src]

impl Unpin for Ssr[src]

impl !UnwindSafe for Ssr[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,