feat: serve static upload app from axum
Introduce the first PLAN.md milestone: replace the hello-world binary with an Axum server that binds to localhost by default, exposes a health endpoint, and serves the static browser UI from the repository's static directory. The router is available through the library crate so integration tests can exercise server behavior without opening a network listener. Add a justfile for routine validation and document the initial project shape, configuration knobs, and reusable test checklist. The rustfmt config now uses only stable options so the new formatting recipe runs without nightly warnings. The upload API and resumable chunk behavior are intentionally left for later milestones; the UI currently handles file selection only. Test Plan: - just check Refs: PLAN.md milestone 1
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
use std::net::{Ipv4Addr, SocketAddr};
|
||||
|
||||
use axum::{body::Body, http::Request};
|
||||
use http_body_util::BodyExt;
|
||||
use tower::ServiceExt;
|
||||
use upl::app::{AppConfig, build_router};
|
||||
|
||||
#[tokio::test]
|
||||
async fn serves_index_page() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let app = test_app();
|
||||
|
||||
let response = app
|
||||
.oneshot(Request::builder().uri("/").body(Body::empty())?)
|
||||
.await?;
|
||||
|
||||
assert_eq!(response.status(), axum::http::StatusCode::OK);
|
||||
|
||||
let body = response.into_body().collect().await?.to_bytes();
|
||||
let body = String::from_utf8(body.to_vec())?;
|
||||
|
||||
assert!(body.contains("<title>upl</title>"));
|
||||
assert!(body.contains("Select file"));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reports_health() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let app = test_app();
|
||||
|
||||
let response = app
|
||||
.oneshot(Request::builder().uri("/healthz").body(Body::empty())?)
|
||||
.await?;
|
||||
|
||||
assert_eq!(response.status(), axum::http::StatusCode::OK);
|
||||
|
||||
let body = response.into_body().collect().await?.to_bytes();
|
||||
assert_eq!(body.as_ref(), b"ok");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn test_app() -> axum::Router {
|
||||
build_router(&AppConfig::new(
|
||||
SocketAddr::from((Ipv4Addr::LOCALHOST, 0)),
|
||||
concat!(env!("CARGO_MANIFEST_DIR"), "/static"),
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user