Function leptos_axum::render_app_to_stream
source · pub fn render_app_to_stream<IV>(
options: LeptosOptions,
app_fn: impl Fn() -> IV + Clone + Send + 'static
) -> impl Fn(Request<Body>) -> Pin<Box<dyn Future<Output = Response<Body>> + Send + 'static>> + Clone + Send + 'staticwhere
IV: IntoView,
Expand description
Returns an Axum Handler that listens for a GET
request and tries
to route it using leptos_router, serving an HTML stream of your application.
The provides a MetaContext and a RouterIntegrationContext to app’s context before rendering it, and includes any meta tags injected using leptos_meta.
The HTML stream is rendered using render_to_stream, and includes everything described in the documentation for that function.
This can then be set up at an appropriate route in your application:
use axum::{handler::Handler, Router};
use leptos::*;
use leptos_config::get_configuration;
use std::{env, net::SocketAddr};
#[component]
fn MyApp() -> impl IntoView {
view! { <main>"Hello, world!"</main> }
}
#[cfg(feature = "default")]
#[tokio::main]
async fn main() {
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
let leptos_options = conf.leptos_options;
let addr = leptos_options.site_addr.clone();
// build our application with a route
let app = Router::new().fallback(leptos_axum::render_app_to_stream(
leptos_options,
|| view! { <MyApp/> },
));
// run our app with hyper
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
}
§Provided Context Types
This function always provides context values including the following types: