Files
logaritmisk 7170be016d feat(server): embed SPA via memory-serve behind embed-web feature
Adds `memory-serve` 2.1 as an optional workspace dependency, a `build.rs`
that runs `load_directory` only when `CARGO_FEATURE_EMBED_WEB` is set, a
`web_assets` module serving `web/dist` at `/` with SPA fallback (200 OK)
for unknown client-side routes, and a feature-gated integration test.

The default build (no feature) compiles and tests cleanly without `web/dist`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-03 23:22:26 +02:00

38 lines
976 B
Rust

//! Only meaningful with `--features embed-web` and a built `web/dist`. Compiled only
//! under that feature.
#![cfg(feature = "embed-web")]
use axum::body::Body;
use axum::http::{Request, StatusCode};
use http_body_util::BodyExt;
use tower::ServiceExt;
#[tokio::test]
async fn serves_index_at_root_and_spa_fallback() {
let app = server::test_support::web_router();
let root = app
.clone()
.oneshot(Request::builder().uri("/").body(Body::empty()).unwrap())
.await
.unwrap();
assert_eq!(root.status(), StatusCode::OK);
let body = root.into_body().collect().await.unwrap().to_bytes();
assert!(String::from_utf8_lossy(&body).contains("<div id=\"root\">"));
let deep = app
.oneshot(
Request::builder()
.uri("/objects/123")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(deep.status(), StatusCode::OK);
}