From 380f67c9e9d6cfc2b23a0cfb1d893ae83cbb42e9 Mon Sep 17 00:00:00 2001 From: Ovidiu Stinga Date: Fri, 20 Dec 2024 13:24:33 +0200 Subject: [PATCH] Port server to async -- Closes #2 --- crates/server/Cargo.toml | 1 + crates/server/src/main.rs | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index c64f060..35bf364 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" miniserve = { path = "../miniserve" } serde = { version = "1.0.216", features = ["derive"] } serde_json = "1.0.133" +tokio = { workspace = true, features = ["full"] } diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 4b1f989..7418132 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs @@ -13,12 +13,12 @@ struct ChatResponse { messages: Vec, } -fn index(_req: Request) -> Response { +async fn index(_req: Request) -> Response { let content = include_str!("../index.html").to_string(); Ok(Content::Html(content)) } -fn chat(req: Request) -> Response { +async fn chat(req: Request) -> Response { match req { Request::Get => Err(http::StatusCode::METHOD_NOT_ALLOWED), Request::Post(body) => { @@ -35,9 +35,11 @@ fn chat(req: Request) -> Response { } } -fn main() { +#[tokio::main] +async fn main() { miniserve::Server::new() .route("/", index) .route("/chat", chat) .run() + .await }