File tree Expand file tree Collapse file tree 3 files changed +17
-17
lines changed
Expand file tree Collapse file tree 3 files changed +17
-17
lines changed Original file line number Diff line number Diff line change @@ -11,4 +11,5 @@ path = "src/main.rs"
1111name = " coduck-backend"
1212
1313[dependencies ]
14- rocket = " 0.5.1"
14+ axum = " 0.8.4"
15+ tokio = { version = " 1.45.1" , features = [" full" ] }
Original file line number Diff line number Diff line change 1- #[ macro_use]
2- extern crate rocket;
1+ use axum:: { routing:: get, Router } ;
32
4- use rocket:: { Build , Rocket } ;
5-
6- #[ get( "/health_check" ) ]
7- fn health_check ( ) {
8- ( )
3+ async fn health_check ( ) -> & ' static str {
4+ "OK"
95}
106
11- pub fn run ( ) -> Rocket < Build > {
12- rocket :: build ( ) . mount ( "/" , routes ! [ health_check] )
7+ pub fn build_router ( ) -> Router {
8+ Router :: new ( ) . route ( "/health " , get ( health_check) )
139}
Original file line number Diff line number Diff line change 1- use coduck_backend:: run;
2-
3- #[ rocket:: main]
1+ #[ tokio:: main]
42async fn main ( ) {
5- if let Err ( e) = run ( ) . launch ( ) . await {
6- println ! ( "Failed to launch Rocket: {e}" ) ;
7- drop ( e) ;
8- }
3+ let app = coduck_backend:: build_router ( ) ;
4+
5+ let listener = tokio:: net:: TcpListener :: bind ( "127.0.0.1:8080" )
6+ . await
7+ . unwrap ( ) ;
8+ println ! ( "Listening on {}" , listener. local_addr( ) . unwrap( ) ) ;
9+ axum:: serve ( listener, app)
10+ . await
11+ . expect ( "Server failed to start" ) ;
912}
You can’t perform that action at this time.
0 commit comments