pub struct Ssr { /* private fields */ }
Expand description
The main struct of the crate that manages Node.js process and handles rendering.
Implementations§
source§impl Ssr
impl Ssr
sourcepub async fn render<D: Serialize>(
&self,
uri: &Uri,
data: &D,
js_renderer: JsRenderer
) -> Result<String, RenderingError>
pub async fn render<D: Serialize>( &self, uri: &Uri, data: &D, js_renderer: JsRenderer ) -> Result<String, RenderingError>
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()
}
}