fix: guard embedded frontend assets
This commit is contained in:
+11
-1
@@ -14,6 +14,9 @@ use tower_http::services::ServeDir;
|
||||
|
||||
static EMBEDDED_WEB: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/dist/web");
|
||||
static EMBEDDED_WEBSITE: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/dist/website");
|
||||
const _: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/dist/web/index.html"));
|
||||
const _: &[u8] =
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/dist/website/index.html"));
|
||||
|
||||
mod admin;
|
||||
mod auth;
|
||||
@@ -187,6 +190,11 @@ async fn embedded_static_handler(req: Request<Body>) -> Response {
|
||||
return embedded_file_response("index.html", file.contents());
|
||||
}
|
||||
|
||||
let disk_fallback = filesystem_static_response(path, "dist/web", "dist/website").await;
|
||||
if disk_fallback.status() != StatusCode::NOT_FOUND {
|
||||
return disk_fallback;
|
||||
}
|
||||
|
||||
if should_serve_website(path) && EMBEDDED_WEBSITE.get_file("index.html").is_none() {
|
||||
if let Some(file) = EMBEDDED_WEB.get_file("index.html") {
|
||||
return embedded_file_response("index.html", file.contents());
|
||||
@@ -196,7 +204,9 @@ async fn embedded_static_handler(req: Request<Body>) -> Response {
|
||||
Response::builder()
|
||||
.status(StatusCode::NOT_FOUND)
|
||||
.header(header::CONTENT_TYPE, "text/plain; charset=utf-8")
|
||||
.body(Body::from("embedded frontend index.html not found"))
|
||||
.body(Body::from(
|
||||
"embedded frontend index.html not found; rebuild with ./build-and-run.sh --production or set BOOSAPI_WEB_DIR/BOOSAPI_WEBSITE_DIR",
|
||||
))
|
||||
.unwrap_or_else(|_| StatusCode::NOT_FOUND.into_response())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user