Files
xevion.dev/src/assets.rs
Xevion 81d9541b44 feat: add health checks, OG image generation, and R2 integration
- Implement health check system with caching and singleflight pattern
- Add OG image generation via Satori with R2 storage backend
- Configure Railway deployment with health check endpoint
- Add connection pooling and Unix socket support for Bun SSR
- Block external access to internal routes (/internal/*)
2026-01-05 03:16:55 -06:00

49 lines
1.5 KiB
Rust

use axum::{
http::{StatusCode, Uri, header},
response::{IntoResponse, Response},
};
use include_dir::{Dir, include_dir};
static CLIENT_ASSETS: Dir = include_dir!("$CARGO_MANIFEST_DIR/web/build/client");
pub async fn serve_embedded_asset(uri: Uri) -> Response {
let path = uri.path();
let asset_path = path.strip_prefix('/').unwrap_or(path);
match CLIENT_ASSETS.get_file(asset_path) {
Some(file) => {
let mime_type = mime_guess::from_path(asset_path)
.first_or_octet_stream()
.as_ref()
.to_string();
let mut headers = axum::http::HeaderMap::new();
headers.insert(
header::CONTENT_TYPE,
mime_type.parse().unwrap_or_else(|_| {
header::HeaderValue::from_static("application/octet-stream")
}),
);
if path.contains("/immutable/") {
headers.insert(
header::CACHE_CONTROL,
header::HeaderValue::from_static("public, max-age=31536000, immutable"),
);
} else {
headers.insert(
header::CACHE_CONTROL,
header::HeaderValue::from_static("public, max-age=3600"),
);
}
(StatusCode::OK, headers, file.contents()).into_response()
}
None => {
tracing::debug!(path, "Embedded asset not found");
(StatusCode::NOT_FOUND, "Asset not found").into_response()
}
}
}