mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 13:07:39 +00:00
fix(gateway): return 404 for missing static assets instead of SPA fallback (#12060)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 32d2ca7a13
Co-authored-by: mcaxtr <7562095+mcaxtr@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
This commit is contained in:
@@ -61,6 +61,28 @@ function contentTypeForExt(ext: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extensions recognised as static assets. Missing files with these extensions
|
||||
* return 404 instead of the SPA index.html fallback. `.html` is intentionally
|
||||
* excluded — actual HTML files on disk are served earlier, and missing `.html`
|
||||
* paths should fall through to the SPA router (client-side routers may use
|
||||
* `.html`-suffixed routes).
|
||||
*/
|
||||
const STATIC_ASSET_EXTENSIONS = new Set([
|
||||
".js",
|
||||
".css",
|
||||
".json",
|
||||
".map",
|
||||
".svg",
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".webp",
|
||||
".ico",
|
||||
".txt",
|
||||
]);
|
||||
|
||||
export type ControlUiAvatarResolution =
|
||||
| { kind: "none"; reason: string }
|
||||
| { kind: "local"; filePath: string }
|
||||
@@ -327,6 +349,16 @@ export function handleControlUiHttpRequest(
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the requested path looks like a static asset (known extension), return
|
||||
// 404 rather than falling through to the SPA index.html fallback. We check
|
||||
// against the same set of extensions that contentTypeForExt() recognises so
|
||||
// that dotted SPA routes (e.g. /user/jane.doe, /v2.0) still get the
|
||||
// client-side router fallback.
|
||||
if (STATIC_ASSET_EXTENSIONS.has(path.extname(fileRel).toLowerCase())) {
|
||||
respondNotFound(res);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SPA fallback (client-side router): serve index.html for unknown paths.
|
||||
const indexPath = path.join(root, "index.html");
|
||||
if (fs.existsSync(indexPath)) {
|
||||
|
||||
Reference in New Issue
Block a user