Initial
This commit is contained in:
5
crates/erplt-api/src/lib.rs
Normal file
5
crates/erplt-api/src/lib.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
mod routes;
|
||||
mod state;
|
||||
mod server;
|
||||
|
||||
pub use server::start;
|
||||
3
crates/erplt-api/src/routes/health.rs
Normal file
3
crates/erplt-api/src/routes/health.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub async fn get() -> &'static str {
|
||||
"OK"
|
||||
}
|
||||
8
crates/erplt-api/src/routes/mod.rs
Normal file
8
crates/erplt-api/src/routes/mod.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use axum::{routing::get, Router};
|
||||
|
||||
mod health;
|
||||
|
||||
pub fn router() -> Router {
|
||||
Router::new()
|
||||
.route("/health", get(health::get))
|
||||
}
|
||||
33
crates/erplt-api/src/server.rs
Normal file
33
crates/erplt-api/src/server.rs
Normal 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(())
|
||||
}
|
||||
0
crates/erplt-api/src/state.rs
Normal file
0
crates/erplt-api/src/state.rs
Normal file
Reference in New Issue
Block a user