From 841fa7e91e6c8d388d61adb56a7ba35649e91d43 Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Sun, 10 May 2026 08:33:42 -0700 Subject: [PATCH] Just got axum up and running. Spent waaaay too long wrestling with rustic and rustfmt to get it to stop throwing errors, only to realize that the actual problem was my copy of rustfmt being waaaay out of date. With that fixed, the problem went away. --- demo/rustfmt.toml | 1 + demo/src/main.rs | 38 ++++++++++++++++++++++++++++++++++++-- rustfmt.toml | 1 + serve_zip/rustfmt.toml | 1 + 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 demo/rustfmt.toml create mode 100644 rustfmt.toml create mode 100644 serve_zip/rustfmt.toml diff --git a/demo/rustfmt.toml b/demo/rustfmt.toml new file mode 100644 index 0000000..3a26366 --- /dev/null +++ b/demo/rustfmt.toml @@ -0,0 +1 @@ +edition = "2021" diff --git a/demo/src/main.rs b/demo/src/main.rs index e7a11a9..85ddfe9 100644 --- a/demo/src/main.rs +++ b/demo/src/main.rs @@ -1,3 +1,37 @@ -fn main() { - println!("Hello, world!"); +use axum::{routing::get, Router}; +use clap::Parser; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use std::path::PathBuf; +use tokio::net::TcpListener; + +#[derive(Parser)] +struct Args { + #[arg(short, long)] + zip: Option, + + #[arg(short, long, default_value = "8001")] + port: u16, +} + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt::init(); + let args = Args::parse(); + + // TODO: Add a test to see if `path`, if it exists, is a path to a folder or to a zip file. If a + // folder, opt for using serve_dir instead. + match &args.zip { + Some(path) => println!("Using external zip file: {}", path.display()), + None => { + println!("Using embedded zip file, if present. (TODO: Make this an error otherwise)") + } + } + + let app = Router::new().route("/check", get(|| async { "OK" })); + let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), args.port); + let listener = TcpListener::bind(addr) + .await + .expect("Failed to bind to port"); + println!("Listening at {}", addr); + axum::serve(listener, app).await.unwrap(); } diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..3a26366 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +edition = "2021" diff --git a/serve_zip/rustfmt.toml b/serve_zip/rustfmt.toml new file mode 100644 index 0000000..3a26366 --- /dev/null +++ b/serve_zip/rustfmt.toml @@ -0,0 +1 @@ +edition = "2021"