axum + Astro, shipped as one binary. Static pages served from disk in dev, embedded in the executable in release.
Astrum
axum + Astro, shipped as one binary.
Astro builds static pages. axum serves them: from disk while you develop, from
inside the executable in release. There is no astro dev and no second port.
Requirements
rust, bun, and watchexec (for dev.sh).
Develop
./dev.sh
Opens on http://127.0.0.1:8080. It installs frontend dependencies on first run, then watches two things at once:
- Rust changes restart the server (watchexec).
- Anything under
frontend/makes the server runbun run buildand pushreloadto every browser on/dev-ws.
Build for production
./build.sh # -> backend/target/release/astrum
That rebuilds the frontend without PUBLIC_HOT_RELOAD, then compiles with
--no-default-features so the watcher, bun and /dev-ws are left out
entirely. The result is one self-contained file; copy it anywhere and run it.
How hot reload is wired
| Where | What |
|---|---|
backend/src/dev.rs |
Runs bun run build with PUBLIC_HOT_RELOAD=true, watches frontend/, broadcasts to /dev-ws. |
frontend/src/components/DevReload.astro |
Emits the client script only when PUBLIC_HOT_RELOAD === "true", so a production page has none of it. |
hot-reload cargo feature |
Compiles all of the above in. On by default; --no-default-features drops it and the notify dependency. |
The env var is what connects the two halves: the Rust side sets it when it invokes bun, and the Astro build decides from it whether the page opens a socket at all.
Environment
| Variable | Default | Meaning |
|---|---|---|
HOST |
127.0.0.1 |
Bind address. |
PORT |
8080 |
Bind port. |
FRONTEND_WATCH |
on in debug, off in release | Rebuild the frontend and serve reloads. |
DEBOUNCE_MILLIS |
500 |
Quiet period after an edit before rebuilding. |
RUST_LOG |
info |
Log filter. |
Layout
backend/
build.rs cargo can't see frontend/dist; this makes it rebuild when it changes
src/main.rs routes, config, startup
src/frontend.rs serves dist: disk in debug, embedded in release
src/dev.rs bun rebuild, file watcher, /dev-ws
frontend/
src/pages/ one file per route (index, about, 404)
src/layouts/ page shell
src/components/ DevReload
src/styles/ Tailwind entry and theme tokens
Notes
frontend/disthas to exist before the server compiles, sincerust-embedreads it at compile time.dev.shandbuild.shboth handle that.- Astro emits
about/index.html; the server resolves/aboutand/about/to it, and unknown paths get404.astro. - Add a route in axum by adding to the router in
main.rs. Add a page by dropping a.astrofile infrontend/src/pages/.