added a server

This commit is contained in:
2026-07-29 06:43:43 +08:00
parent c786295ea9
commit 397643ae01
5 changed files with 146 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
[package]
name = "wyd-server"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
axum = "0.8"
tokio = { version = "1.53.1", features = ["macros", "net", "rt-multi-thread"] }
+17
View File
@@ -0,0 +1,17 @@
use std::env;
use axum::{http::StatusCode, routing::get, Router};
#[tokio::main]
async fn main() -> std::io::Result<()> {
let bind_addr = env::var("BIND_ADDR").unwrap_or_else(|_| "127.0.0.1:3000".to_string());
let listener = tokio::net::TcpListener::bind(&bind_addr).await?;
let app = Router::new()
.route("/", get("ok"))
.route("/health", get("ok"))
.fallback((StatusCode::NOT_FOUND, "not found"));
println!("wyd-server listening on http://{bind_addr}");
axum::serve(listener, app).await
}