Skip to content

Commit

Permalink
modify to change zero2prod to be a library
Browse files Browse the repository at this point in the history
  • Loading branch information
nathannli committed Mar 31, 2024
1 parent 24b8c2c commit d7810a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use actix_web::dev::Server;
use actix_web::{web, App, HttpResponse, HttpServer};

async fn health_check() -> HttpResponse {
HttpResponse::Ok().finish()
}

pub fn run() -> Result<Server, std::io::Error> {
let server = HttpServer::new(|| App::new().route("/health_check", web::get().to(health_check)))
.bind("127.0.0.1:8000")?
.run();
Ok(server)
}
21 changes: 2 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
use actix_web::{web, App, HttpResponse, HttpServer, Responder};

// async fn greet(req: HttpRequest) -> impl Responder {
// let name = req.match_info().get("name").unwrap_or("World");
// format!("Hello {}!", &name)
// }

async fn health_check() -> impl Responder {
HttpResponse::Ok()
}
use zero2prod::run;

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
HttpServer::new(|| {
App::new()
// .route("/", web::get().to(greet))
// .route("/{name}", web::get().to(greet))
.route("/health_check", web::get().to(health_check))
})
.bind("127.0.0.1:8000")?
.run()
.await
run()?.await
}

0 comments on commit d7810a5

Please sign in to comment.