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"