2023-07-14 22:43:19 +01:00
|
|
|
#[cfg(feature = "ssr")]
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
use axum::{routing::post, Router};
|
2023-09-12 15:24:32 +01:00
|
|
|
use leptos::logging::log;
|
2023-07-14 22:43:19 +01:00
|
|
|
use leptos::*;
|
|
|
|
use leptos_axum::{generate_route_list, LeptosRoutes};
|
2023-10-21 15:21:11 -05:00
|
|
|
use leptos_use_ssr::app::*;
|
|
|
|
use leptos_use_ssr::fileserv::file_and_error_handler;
|
2023-07-14 22:43:19 +01:00
|
|
|
|
2024-01-10 23:37:32 +00:00
|
|
|
simple_logger::init_with_level(log::Level::Info).expect("couldn't initialize logging");
|
2023-07-14 22:43:19 +01:00
|
|
|
|
|
|
|
// Setting get_configuration(None) means we'll be using cargo-leptos's env values
|
|
|
|
// For deployment these variables are:
|
|
|
|
// <https://github.com/leptos-rs/start-axum#executing-a-server-on-a-remote-machine-without-the-toolchain>
|
|
|
|
// Alternately a file can be specified such as Some("Cargo.toml")
|
|
|
|
// The file would need to be included with the executable when moved to deployment
|
|
|
|
let conf = get_configuration(None).await.unwrap();
|
|
|
|
let leptos_options = conf.leptos_options;
|
|
|
|
let addr = leptos_options.site_addr;
|
2023-10-21 15:21:11 -05:00
|
|
|
let routes = generate_route_list(|| view! { <App/> });
|
2023-07-14 22:43:19 +01:00
|
|
|
|
|
|
|
// build our application with a route
|
|
|
|
let app = Router::new()
|
|
|
|
.route("/api/*fn_name", post(leptos_axum::handle_server_fns))
|
2023-07-27 18:06:36 +01:00
|
|
|
.leptos_routes(&leptos_options, routes, || view! { <App/> })
|
2023-07-14 22:43:19 +01:00
|
|
|
.fallback(file_and_error_handler)
|
|
|
|
.with_state(leptos_options);
|
|
|
|
|
2024-01-31 16:54:25 +00:00
|
|
|
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
2023-07-14 22:43:19 +01:00
|
|
|
log!("listening on http://{}", &addr);
|
2024-01-31 16:54:25 +00:00
|
|
|
axum::serve(listener, app.into_make_service())
|
2023-07-14 22:43:19 +01:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "ssr"))]
|
|
|
|
pub fn main() {
|
|
|
|
// no client-side main function
|
|
|
|
// unless we want this to work with e.g., Trunk for a purely client-side app
|
|
|
|
// see lib.rs for hydration function instead
|
|
|
|
}
|