2024-01-25 02:40:50 -05:00
|
|
|
use app::*;
|
2024-01-26 18:09:06 -05:00
|
|
|
use axum::Router;
|
2024-01-25 02:40:50 -05:00
|
|
|
use fileserv::file_and_error_handler;
|
|
|
|
use leptos::*;
|
2024-01-25 15:15:22 -05:00
|
|
|
use leptos_axum::{build_static_routes, generate_route_list_with_exclusions_and_ssg, LeptosRoutes};
|
2024-01-25 02:40:50 -05:00
|
|
|
|
|
|
|
pub mod fileserv;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
simple_logger::init_with_level(log::Level::Debug).expect("couldn't initialize logging");
|
|
|
|
|
|
|
|
// 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;
|
2024-01-25 15:15:22 -05:00
|
|
|
let (routes, data) = generate_route_list_with_exclusions_and_ssg(App, None);
|
|
|
|
build_static_routes(&leptos_options, App, &routes, data).await;
|
2024-01-25 02:40:50 -05:00
|
|
|
|
|
|
|
// build our application with a route
|
|
|
|
let app = Router::new()
|
|
|
|
.leptos_routes(&leptos_options, routes, App)
|
|
|
|
.fallback(file_and_error_handler)
|
|
|
|
.with_state(leptos_options);
|
|
|
|
|
|
|
|
// run our app with hyper
|
|
|
|
// `axum::Server` is a re-export of `hyper::Server`
|
2024-01-26 18:09:06 -05:00
|
|
|
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
2024-01-25 02:40:50 -05:00
|
|
|
log::info!("listening on http://{}", &addr);
|
2024-01-26 18:09:06 -05:00
|
|
|
axum::serve(listener, app.into_make_service())
|
2024-01-25 02:40:50 -05:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|