Migrate from Trillium [part 8A]: Move assets to Axum (tower-http ServeDir)#2250
Closed
Migrate from Trillium [part 8A]: Move assets to Axum (tower-http ServeDir)#2250
Conversation
…rectly Axum is now the primary HTTP listener. The Trillium server, which was a pure pass-through proxy since Part 7C, is removed from the request path. Production changes: - `build_app(Config) -> BuiltApp` replaces `DivviupApi` for production use - `bin.rs` rewritten: Axum serves directly, monitoring server is a separate Axum router, graceful shutdown via tokio signals + CancellationToken - `Queue` uses `CancellationToken` instead of Trillium's `Stopper`/`CloneCounterObserver` - `telemetry.rs` and `trace.rs` handlers converted from Trillium to Axum - `Config` gains `listen_address` field (from HOST/PORT env vars, default [::]:8080) Dead code removal: - Deleted: `handler/logger.rs`, `handler/opentelemetry.rs`, `axum_proxy` test - Removed `FromConn` impls from: `Db`, `User`, `PermissionsActor`, `AccountBearerToken` - Removed Trillium `Handler` impls from: `Db`, `ErrorHandler`, `CorsHeaders`, `ReplaceMimeTypes`, `SessionStore` - Unified `PermissionsActor::is_allowed`/`if_allowed` to use `http::Method` - Removed deps: `trillium-compression`, `trillium-conn-id`, `trillium-forwarding`, `trillium-opentelemetry`, `trillium-prometheus`, `trillium-redirect`, `trillium-sessions`, `trillium-cookies`, `async-session` - Added deps: `cookie` (key-expansion feature, for session key derivation) `DivviupApi` is kept as a thin test-only shim that spawns Axum on [::1]:0 and proxies via the existing `AxumProxy`, preserving test-support compatibility. Full test-support rewrite is deferred to Part 9.
…eDir) Replace the Trillium-based static asset handler (`trillium-static-compiled` + `OriginRouter`) with an Axum middleware using `tower-http`'s `ServeDir` and `ServeFile`. The middleware intercepts requests whose `Host` (or `X-Forwarded-Host`) matches the configured `app_url` and serves the React SPA with appropriate `cache-control` headers (`max-age=1year` for `/assets/*`, `no-cache` for everything else). Unmatched hosts pass through to the API routes. The proxy now forwards the original `Host` as `X-Forwarded-Host` so Axum can perform host-based routing. Note!!: assets are no longer embedded at compile time — they are served from the filesystem at runtime. This is fine, we included them in the Docker build anyway. The `ASSET_DIR` env var still controls whether asset support is compiled in.
Contributor
Author
|
Splitting this out is proving to be more headache than it's worth. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the Trillium-based static asset handler (
trillium-static-compiled+OriginRouter) with an Axum middleware usingtower-http'sServeDirandServeFile.The middleware intercepts requests whose
Host(orX-Forwarded-Host) matches the configuredapp_urland serves the React SPA with appropriatecache-controlheaders (max-age=1yearfor/assets/*,no-cachefor everything else). Unmatched hosts pass through to the API routes.The proxy now forwards the original
HostasX-Forwarded-Hostso Axum can perform host-based routing.Note
assets are no longer embedded at compile time — they are served from the filesystem at runtime. This is fine, we included them in the Docker build anyway. The
ASSET_DIRenv var still controls whether asset support is compiled in.