tirbofish/kitgit
main / src / main.rs · 1552 bytes
src/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
54
55
56
57
58
59
60
mod auth;
mod config;
mod db;
mod git;
mod highlight;
mod markdown;
mod mfa;
mod og;
mod state;
mod web;
mod webhooks;
use crate::auth::AuthState;
use crate::config::Config;
use crate::state::AppState;
use anyhow::Result;
use std::sync::Arc;
use tracing_subscriber::EnvFilter;
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
)
.init();
let config = Config::load()?;
let config = Arc::new(config);
std::fs::create_dir_all(config.repos_dir())?;
std::fs::create_dir_all(config.avatars_dir())?;
std::fs::create_dir_all(config.releases_dir())?;
std::fs::create_dir_all(config.data_dir.join("lfs"))?;
std::fs::create_dir_all(&config.data_dir)?;
let pool = db::connect(&config.database_url).await?;
db::migrate(&pool, std::path::Path::new("./migrations")).await?;
let auth = AuthState::new(pool.clone(), config.clone()).await?;
let state = AppState {
pool,
config: config.clone(),
auth,
};
let ssh_state = state.clone();
tokio::spawn(async move {
if let Err(e) = git::ssh::run_ssh(ssh_state).await {
tracing::error!("ssh server exited: {e:#}");
}
});
let app = web::app_router(state);
let listener = tokio::net::TcpListener::bind(config.http_bind).await?;
tracing::info!("http listening on {}", config.http_bind);
axum::serve(listener, app).await?;
Ok(())
}