Built for people who think better out loud.

backend: Refactor routes

isaaccorbrey.com f51c28c5 ec29ef33

verified
+23 -15
+5 -15
backend/src/main.rs
··· 1 - use axum::{Router, routing::get}; 2 1 use tokio::net::TcpListener; 2 + 3 + mod routers; 3 4 4 5 #[tokio::main] 5 6 async fn main() { 6 - let app = Router::new() 7 - .route("/", get(root)) 8 - .route("/health", get(health)); 9 - 10 - let listener = TcpListener::bind("0.0.0.0:3000") 7 + let app = routers::router(); 8 + let listener = TcpListener::bind("0.0.0.0:3001") 11 9 .await 12 - .expect("failed to bind to 0.0.0.0:3000"); 10 + .expect("failed to bind to 0.0.0.0:3001"); 13 11 14 12 axum::serve(listener, app) 15 13 .await 16 14 .expect("axum server failed"); 17 15 } 18 - 19 - async fn root() -> &'static str { 20 - "slipnote backend" 21 - } 22 - 23 - async fn health() -> &'static str { 24 - "ok" 25 - }
+10
backend/src/routers/health.rs
··· 1 + use axum::{Router, routing::get}; 2 + 3 + pub fn router() -> Router { 4 + Router::new() 5 + .route("/health", get(health)) 6 + } 7 + 8 + async fn health() -> &'static str { 9 + "ok" 10 + }
+8
backend/src/routers/mod.rs
··· 1 + use axum::Router; 2 + 3 + mod health; 4 + 5 + pub fn router() -> Router { 6 + Router::new() 7 + .merge(health::router()) 8 + }