-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.rs
53 lines (40 loc) · 1.23 KB
/
main.rs
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
// SPDX-FileCopyrightText: 2023 Christina Sørensen
// SPDX-FileContributor: Christina Sørensen
//
// SPDX-License-Identifier: AGPL-3.0-only
#![deny(clippy::unwrap_used)]
use axum::{extract::Extension, response::Redirect, routing::get, Router};
use tokio::net::TcpListener;
extern crate log;
extern crate pretty_env_logger;
mod api;
mod cli;
mod data;
use api::routes::get_routes as get_api_routes;
#[allow(unused)]
use log::{debug, error, info, trace, warn};
#[tokio::main]
async fn main() {
pretty_env_logger::init();
let matches = crate::cli::build_cli().get_matches();
let config;
if let Some(config_file) = matches.get_one::<String>("config") {
config = crate::data::Config::load(config_file);
} else {
config = crate::data::Config::load(data::CONFIG);
}
trace!("{config:#?}");
let app = Router::new()
.route(
"/",
get(|| async { Redirect::to("https://github.com/cafkafk/rime") }),
)
.merge(get_api_routes())
.layer(Extension(config.clone()));
let listener = TcpListener::bind(&config.bind_addr())
.await
.expect("failed to bind");
axum::serve(listener, app)
.await
.expect("failed to serve app");
}