From 09e40b4af7cd14f22704be52730a84c8c2d5d38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20M=C3=BCller?= Date: Fri, 6 Mar 2026 16:00:00 +0000 Subject: [PATCH] Wire up router in main.rs --- Cargo.toml | 4 ++++ src/main.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 2ff2686..786f389 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,3 +21,7 @@ thiserror = "1" [dev-dependencies] tokio-test = "0.4" reqwest = { version = "0.12", features = ["json"] } + +[[bin]] +name = "nexus-api" +path = "src/main.rs" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..bcf0762 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,27 @@ +mod api; +mod auth; +mod db; +mod middleware; +mod models; + +use axum::{middleware as axum_middleware, routing::get, Router}; +use std::env; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + tracing_subscriber::fmt::init(); + let pool = db::pool::create_pool().await?; + let port = env::var("PORT").unwrap_or("8080".into()); + + let app = Router::new() + .route("/health", get(api::health::health_check)) + .route("/api/v1/users", get(api::users::list_users)) + .route("/api/v1/users/:id", get(api::users::get_user)) + .route_layer(axum_middleware::from_fn(middleware::auth::require_auth)) + .with_state(pool); + + let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{port}")).await?; + tracing::info!("Listening on port {port}"); + axum::serve(listener, app).await?; + Ok(()) +}