Files
biggus-dickus/crates/server/src/web_assets.rs
T
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

16 lines
635 B
Rust

//! Serves the embedded SPA (built `web/dist`) at `/` with a client-side-routing
//! fallback. Compiled only with the `embed-web` feature; in dev the SPA is served by
//! Vite (which proxies `/api` to this server), so this module is absent.
use axum::{Router, http::StatusCode};
/// A router that serves the embedded `web/dist` assets, falling back to `index.html`
/// for unknown paths so the SPA can own client-side routes.
pub(crate) fn routes() -> Router {
memory_serve::load!()
.index_file(Some("/index.html"))
.fallback(Some("/index.html"))
.fallback_status(StatusCode::OK)
.into_router()
}