#![deny( warnings, nonstandard_style, unused, future_incompatible, rust_2018_idioms, unsafe_code )] #![deny(clippy::all, clippy::nursery, clippy::pedantic)] #![recursion_limit = "128"] #![allow(clippy::cast_precision_loss, clippy::significant_drop_tightening)] mod modules; mod notion; mod response; mod route; mod timing; mod url; mod xml; #[macro_use] extern crate log; use { // dotenv::var, pickledb::PickleDb, std::sync::{LazyLock, Mutex}, tokio::time::Instant, }; use {std::alloc::System, windmark::router_option::RouterOption}; #[global_allocator] static A: System = System; const ERROR_HANDLER_RESPONSE: &str = "The requested resource could not be found at this time. You can try \ refreshing the page, if that doesn't change anything; contact Fuwn! \ (contact@fuwn.me)"; static DATABASE: LazyLock> = LazyLock::new(|| { Mutex::new({ if std::fs::File::open(".locus/locus.db").is_ok() { PickleDb::load_json( ".locus/locus.db", pickledb::PickleDbDumpPolicy::AutoDump, ) .unwrap() } else { PickleDb::new_json( ".locus/locus.db", pickledb::PickleDbDumpPolicy::AutoDump, ) } }) }); #[windmark::main] async fn main() -> Result<(), Box> { pretty_env_logger::formatted_builder() .parse_filters("windmark,locus=trace") .init(); dotenv::dotenv().ok(); let mut time_mount = Instant::now(); let mut router = windmark::router::Router::new(); router.set_private_key_file(".locus/locus_private.pem"); router.set_certificate_file(".locus/locus_public.pem"); // router.set_private_key(var("LOCUS_PRIVATE_KEY")?.replace("\\n", "\n")); // router.set_certificate(var("LOCUS_CERTIFICATE")?.replace("\\n", "\n")); router.set_error_handler(|_| { windmark::response::Response::not_found(ERROR_HANDLER_RESPONSE) }); router.add_options(&[ RouterOption::RemoveExtraTrailingSlash, RouterOption::AddMissingTrailingSlash, RouterOption::AllowCaseInsensitiveLookup, ]); timing::time_section(&mut time_mount, "creating router"); timing::time_mounts("module", &mut time_mount, || { router.attach_stateless(modules::module); }); std::thread::spawn(modules::search::index); std::thread::spawn(modules::blog::refresh_loop); router.run().await }