- Add libs/frontend crate: build.rs runs pnpm build, copies dist/ to
OUT_DIR/dist_blobs/, generates frontend.rs with lazy_static! map
- libs/api/dist.rs serves embedded assets via serve_frontend handler
- Register /{path:.*} SPA fallback in route.rs (after /api/*)
- Remove frontend container from deploy: docker/frontend.Dockerfile,
deploy/templates/frontend-*.yaml, values.yaml frontend section
- Update ingress: gitdata.ai root now routes to app service
- Update scripts: build.js removes frontend step, deploy.js removes frontend
30 lines
910 B
Rust
30 lines
910 B
Rust
use actix_web::{web, HttpResponse};
|
|
use mime_guess2::MimeGuess;
|
|
|
|
pub async fn serve_frontend(path: web::Path<String>) -> HttpResponse {
|
|
let path = path.into_inner();
|
|
let path = if path.is_empty() || path == "/" {
|
|
"index.html"
|
|
} else {
|
|
&path
|
|
};
|
|
|
|
match frontend::get_frontend_asset(path) {
|
|
Some(data) => {
|
|
let mime = MimeGuess::from_path(path).first_or_octet_stream();
|
|
HttpResponse::Ok()
|
|
.content_type(mime.as_ref())
|
|
.body(data.to_vec())
|
|
}
|
|
None => {
|
|
// Fallback to index.html for SPA routing
|
|
match frontend::get_frontend_asset("index.html") {
|
|
Some(data) => HttpResponse::Ok()
|
|
.content_type("text/html")
|
|
.body(data.to_vec()),
|
|
None => HttpResponse::NotFound().finish(),
|
|
}
|
|
}
|
|
}
|
|
}
|