contact-form/src/main.rs

36 lines
768 B
Rust
Raw Normal View History

2022-10-28 22:41:49 +00:00
mod captcha_solutions;
mod config;
2022-10-29 15:13:12 +00:00
mod context;
2022-10-28 22:41:49 +00:00
mod forms;
mod mailer;
2022-10-26 00:23:55 +00:00
mod routes;
2022-10-29 17:09:56 +00:00
use anyhow::Result;
use rocket::{Build, Rocket};
2022-10-26 00:23:55 +00:00
use rocket_dyn_templates::Template;
2022-10-29 17:09:56 +00:00
use std::process;
2022-10-26 00:23:55 +00:00
2022-10-29 17:09:56 +00:00
fn init() -> Result<Rocket<Build>> {
let mut config = config::Config::new()?;
2022-10-28 22:41:49 +00:00
2022-10-29 17:09:56 +00:00
let rocket = rocket::build()
2022-10-27 16:44:40 +00:00
.mount(
2022-10-28 22:41:49 +00:00
&config.path_prefix,
2022-10-27 16:44:40 +00:00
rocket::routes![routes::index, routes::submit, routes::success],
)
2022-10-28 22:41:49 +00:00
.manage(captcha_solutions::SharedCaptchaSolutions::new())
2022-10-29 17:09:56 +00:00
.manage(mailer::Mailer::new(&mut config)?)
2022-10-28 22:41:49 +00:00
.manage(config)
2022-10-29 17:09:56 +00:00
.attach(Template::fairing());
Ok(rocket)
}
#[rocket::launch]
fn rocket() -> _ {
init().unwrap_or_else(|e| {
eprintln!("{e}");
process::exit(1);
})
2022-10-26 00:23:55 +00:00
}