rieter/server/src/main.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

2023-07-11 13:41:56 +02:00
mod repo;
use axum::extract::FromRef;
2023-07-11 13:41:56 +02:00
use axum::Router;
use repo::RepoGroupManager;
2023-07-11 13:41:56 +02:00
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
2023-07-11 13:41:56 +02:00
#[derive(Clone)]
pub struct Config {
data_dir: PathBuf,
repo_dir: PathBuf,
pkg_dir: PathBuf,
}
#[derive(Clone)]
pub struct Global {
config: Config,
repo_manager: Arc<RwLock<RepoGroupManager>>,
}
impl FromRef<Global> for Arc<RwLock<RepoGroupManager>> {
fn from_ref(global: &Global) -> Self {
Arc::clone(&global.repo_manager)
}
}
2023-07-11 13:41:56 +02:00
#[tokio::main]
async fn main() {
let config = Config {
data_dir: "./data".into(),
repo_dir: "./data/repos".into(),
pkg_dir: "./data/pkgs".into(),
};
let repo_manager = RepoGroupManager::new("./data/repos", "./data/pkgs", "x86_64");
let global = Global {
config,
repo_manager: Arc::new(RwLock::new(repo_manager)),
};
2023-07-11 13:41:56 +02:00
// build our application with a single route
let app = Router::new()
.merge(repo::router(&global))
.with_state(global);
2023-07-11 13:41:56 +02:00
// run it with hyper on localhost:3000
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}