1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#![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! \
([email protected])";
static DATABASE: LazyLock<Mutex<PickleDb>> = 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<dyn std::error::Error>> {
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
}
|