Skip to content

Commit 9b4bf08

Browse files
committed
feat: Replace framework 'rocket' with 'axum'
1 parent 91e36e4 commit 9b4bf08

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ path = "src/main.rs"
1111
name = "coduck-backend"
1212

1313
[dependencies]
14-
rocket = "0.5.1"
14+
axum = "0.8.4"
15+
tokio = { version = "1.45.1", features = ["full"] }

src/lib.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
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
}

src/main.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
use coduck_backend::run;
2-
3-
#[rocket::main]
1+
#[tokio::main]
42
async 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
}

0 commit comments

Comments
 (0)