feat(homelab)!: create interface for homelab management, use templating for route generation & support more options and route types

This commit is contained in:
2026-01-11 14:57:19 -08:00
parent 29cff3bf84
commit 73f8cb91c4
45 changed files with 3907 additions and 109 deletions

View File

@@ -0,0 +1,59 @@
mod endpoints;
mod error;
mod rcon;
use std::env;
use actix_web::{App, HttpServer, web};
use crate::rcon::RconClient;
struct AppState {
rcon: RconClient,
}
struct Env {
rcon_password: String,
}
#[cfg(debug_assertions)]
fn load_env() -> Env {
dotenvy::dotenv().ok();
Env {
rcon_password: env::var("RCON_PASSWORD")
.expect("environment variable RCON_PASSWORD must be set"),
}
}
#[cfg(not(debug_assertions))]
fn load_env() -> Env {
Env {
rcon_password: env::var("RCON_PASSWORD")
.expect("environment variable RCON_PASSWORD must be set"),
}
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let env = load_env();
let app_state = web::Data::new(AppState {
rcon: RconClient::new(env.rcon_password),
});
HttpServer::new(move || {
App::new()
.app_data(app_state.clone())
.route(
"/",
web::get()
.to(async || concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))),
)
.service(web::scope("/api").route(
"/minecraft-server-stats",
web::get().to(endpoints::server_stats::get_server_stats),
))
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}