Wire up router in main.rs
This commit is contained in:
parent
df30f92039
commit
09e40b4af7
2 changed files with 31 additions and 0 deletions
|
|
@ -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"
|
||||
|
|
|
|||
27
src/main.rs
Normal file
27
src/main.rs
Normal file
|
|
@ -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(())
|
||||
}
|
||||
Loading…
Reference in a new issue