fix(registry): serve frontend JS/WASM/CSS correctly in Docker#390
Conversation
**Root cause**: `get_configuration(None)` bakes `site_root = "target/site"` in at compile time. The code had a manual workaround only for CSS — reading `LEPTOS_SITE_ROOT` at runtime to construct the CSS path. But `leptos_options.site_root` itself was never updated, so `file_and_error_handler` (which Leptos uses to serve the JS/WASM from the `pkg/` dir) still pointed at `target/site`, which doesn't exist in the Docker image at `/app/site`.
**Fix** (3 changes to `main.rs`):
1. Override `leptos_options.site_root` from `LEPTOS_SITE_ROOT` at startup — this fixes the root, not the symptom.
2. Replace the custom single-file CSS route handler with `nest_service("/pkg", ServeDir::new(&pkg_dir))` — this serves CSS, JS, and WASM in one shot.
3. Remove the now-unused `use axum::routing::get` import.
In Docker, `LEPTOS_SITE_ROOT=/app/site` is already set in the Dockerfile, so `/pkg/pap-registry-ui.css`, `/pkg/pap-registry-ui.js`, and `/pkg/pap-registry-ui_bg.wasm` will all resolve correctly to `/app/site/pkg/`.
|
| Filename | Overview |
|---|---|
| apps/registry/src/main.rs | Replaces compile-time-baked site_root with a runtime env-var override and swaps the single-file CSS handler for ServeDir over the full pkg directory; logic is sound but the development-mode CSS fallback is silently removed. |
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
apps/registry/src/main.rs:320-325
**Development-mode fallback removed without warning**
The old handler fell back to `apps/registry/styles/main.css` when the compiled artifact wasn't found, so the server stayed usable during `cargo run` before a frontend build. With `ServeDir`, any request to `/pkg/pap-registry-ui.css` (or the JS/WASM siblings) when `pkg_dir` doesn't yet exist returns a silent 404, which can be confusing during local development. A startup log line noting that the `pkg_dir` was not found — or a `tracing::warn!` — would help operators and developers diagnose the missing frontend build faster.
Reviews (1): Last reviewed commit: "Compiles clean. Here's what was wrong an..." | Re-trigger Greptile
| } | ||
| info!("Leptos site root: {}", leptos_options.site_root); | ||
|
|
||
| // Path to the compiled pkg directory (CSS, JS, WASM). | ||
| let pkg_dir = std::path::PathBuf::from(leptos_options.site_root.as_ref()) | ||
| .join(leptos_options.site_pkg_dir.as_ref()); |
There was a problem hiding this comment.
Development-mode fallback removed without warning
The old handler fell back to apps/registry/styles/main.css when the compiled artifact wasn't found, so the server stayed usable during cargo run before a frontend build. With ServeDir, any request to /pkg/pap-registry-ui.css (or the JS/WASM siblings) when pkg_dir doesn't yet exist returns a silent 404, which can be confusing during local development. A startup log line noting that the pkg_dir was not found — or a tracing::warn! — would help operators and developers diagnose the missing frontend build faster.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/registry/src/main.rs
Line: 320-325
Comment:
**Development-mode fallback removed without warning**
The old handler fell back to `apps/registry/styles/main.css` when the compiled artifact wasn't found, so the server stayed usable during `cargo run` before a frontend build. With `ServeDir`, any request to `/pkg/pap-registry-ui.css` (or the JS/WASM siblings) when `pkg_dir` doesn't yet exist returns a silent 404, which can be confusing during local development. A startup log line noting that the `pkg_dir` was not found — or a `tracing::warn!` — would help operators and developers diagnose the missing frontend build faster.
How can I resolve this? If you propose a fix, please make it concise.
Benchmark Regression ReportThreshold: 10% regression vs baseline from main |
Adds a tracing::warn! if the compiled pkg directory does not exist at startup, so developers get a clear diagnostic instead of silent 404s when the frontend has not been built yet. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
get_configuration(None)bakes insite_root = \"target/site\"at compile time;LEPTOS_SITE_ROOTwas only used to find the CSS file, leaving JS/WASM served from the wrong path in Dockerleptos_options.site_rootat startup fromLEPTOS_SITE_ROOTso all Leptos file serving (JS, WASM, CSS) resolves against/app/sitein Dockernest_service(\"/pkg\", ServeDir::new(&pkg_dir))to serve the entire compiled pkg directory uniformlyTest Plan
pap-registryunit tests pass (cargo test -p pap-registry --features ssr)/pkg/pap-registry-ui.css,/pkg/pap-registry-ui.js, and/pkg/pap-registry-ui_bg.wasmreturn 200 in the container🤖 Generated with Claude Code