mod admin; mod howto; mod service; mod state; use crate::service::{handlers, templates}; use crate::state::AppState; use axum::{ extract::State, handler::HandlerWithoutStateExt, response::IntoResponse, routing::get, Router, }; use std::net::SocketAddr; use std::sync::Arc; async fn home(templates: State) -> impl IntoResponse { templates.render_html("index.html", ()) } async fn hello_world(templates: State) -> impl IntoResponse { templates.render_html("hello_world.html", ()) } #[tokio::main] async fn main() { // Prepare App State let tmpl = templates::Templates::initialize().expect("Template Engine could not be loaded."); let mut admin = admin::state::AdminRegistry::new("admin"); admin.register_app("auth", "Authorities", "auth"); let admin_router = admin.generate_router(); let state: AppState = AppState { templates: tmpl, admin: Arc::new(admin), }; // Application Route let app = Router::new() .route("/", get(home)) .route("/hello", get(hello_world)) .merge(admin_router) .nest("/howto", howto::routes()) .route_service("/static/*file", handlers::static_handler.into_service()) .fallback(handlers::not_found_handler) .with_state(state); // Run Server let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); println!("listening on {}", addr); axum::Server::bind(&addr) .serve(app.into_make_service()) .await .unwrap(); }