contact-form/src/main.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2022-10-28 22:41:49 +00:00
mod captcha_solutions;
mod config;
2022-11-01 19:45:06 +00:00
mod errors;
2022-10-28 22:41:49 +00:00
mod forms;
mod mailer;
2022-10-26 00:23:55 +00:00
mod routes;
2022-11-01 19:45:06 +00:00
mod templates;
2022-10-26 00:23:55 +00:00
2022-11-01 19:45:06 +00:00
use anyhow::Result;
2022-10-31 01:13:42 +00:00
use axum::extract::Extension;
use axum::routing::{get, post};
use axum::{Router, Server};
2022-10-29 17:09:56 +00:00
use std::process;
2022-10-31 01:13:42 +00:00
use std::sync::Arc;
async fn init() -> Result<()> {
2022-10-29 17:09:56 +00:00
let mut config = config::Config::new()?;
2022-10-31 01:13:42 +00:00
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))
2022-11-01 19:45:06 +00:00
.layer(Extension(captcha_solutions));
2022-10-31 01:13:42 +00:00
let app = Router::new().nest(&path_prefix, routes);
Server::bind(&([127, 0, 0, 1], 8080).into())
.serve(app.into_make_service())
.await
.unwrap();
2022-10-28 22:41:49 +00:00
2022-10-31 01:13:42 +00:00
Ok(())
2022-10-29 17:09:56 +00:00
}
2022-10-31 01:13:42 +00:00
#[tokio::main]
async fn main() {
init().await.unwrap_or_else(|e| {
2022-10-29 17:09:56 +00:00
eprintln!("{e}");
process::exit(1);
})
2022-10-26 00:23:55 +00:00
}