Skip to content

Commit

Permalink
Port server to async -- Closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ovstinga committed Dec 20, 2024
1 parent c0ea6df commit 380f67c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
8 changes: 5 additions & 3 deletions crates/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ struct ChatResponse {
messages: Vec<String>,
}

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) => {
Expand All @@ -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
}

0 comments on commit 380f67c

Please sign in to comment.