mod captcha_solutions; mod config; mod errors; mod forms; mod mailer; mod routes; mod templates; use anyhow::Result; use axum::extract::Extension; use axum::routing::{get, post}; use axum::{Router, Server}; use std::process; use std::sync::Arc; async fn init() -> Result<()> { let mut config = config::Config::new()?; let path_prefix = config.path_prefix.clone(); let mailer = Arc::new(mailer::Mailer::new(&mut config)?); let config = Arc::new(config); let captcha_solutions = Arc::new(captcha_solutions::SharedCaptchaSolutions::new()); let routes = Router::new() .route("/", get(routes::index)) .route("/submit", post(routes::submit)) .route("/success", get(routes::success)) .layer(Extension(config)) .layer(Extension(mailer)) .layer(Extension(captcha_solutions)); let app = Router::new().nest(&path_prefix, routes); Server::bind(&([127, 0, 0, 1], 8080).into()) .serve(app.into_make_service()) .await .unwrap(); Ok(()) } #[tokio::main] async fn main() { init().await.unwrap_or_else(|e| { eprintln!("{e}"); process::exit(1); }) }