This commit is contained in:
2026-09-07 22:47:34 +03:00
commit 3fcee5ea9a
27 changed files with 1849 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
mod routes;
mod state;
mod server;
pub use server::start;

View File

@@ -0,0 +1,3 @@
pub async fn get() -> &'static str {
"OK"
}

View File

@@ -0,0 +1,8 @@
use axum::{routing::get, Router};
mod health;
pub fn router() -> Router {
Router::new()
.route("/health", get(health::get))
}

View File

@@ -0,0 +1,33 @@
use anyhow::Context;
use axum::http::StatusCode;
use erplt_db::DbPool;
#[axum::debug_handler]
async fn fallback() -> (StatusCode, &'static str) {
(StatusCode::NOT_FOUND, "Not Found")
}
pub async fn start(db: DbPool) -> anyhow::Result<()> {
let config = erplt_config::get();
let app = axum::Router::new()
.merge(crate::routes::router())
.fallback(fallback);
let listener = tokio::net::TcpListener::bind(format!("{}:{}", config.web.host, config.web.port))
.await
.context("Failed to bind HTTP listener")?;
tracing::info!("Web server listening on http://{}", listener.local_addr()?);
axum::serve(listener, app)
.await
.context("Web server stopped unexpectedly")?;
Ok(())
}

View File