From f9006fb467855ae29e6fb49398b67023ffa7336a Mon Sep 17 00:00:00 2001 From: d9k Date: Fri, 29 Dec 2023 20:35:04 +0500 Subject: [PATCH] #292 serve build: return 404 on missing .map requests instead of try to render as HTML --- lib/middleware/serveStatic.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/middleware/serveStatic.ts b/lib/middleware/serveStatic.ts index 4fc9e9f6..cafc5b44 100644 --- a/lib/middleware/serveStatic.ts +++ b/lib/middleware/serveStatic.ts @@ -56,6 +56,15 @@ export const serveStatic = (options: ServeStaticOptions = { root: "" }) => { return; } catch (_error) { + if (path.match("\.map$")) { + log.debug(`Static file: ${path} does not exist, returning 404`); + + return new Response( + null, + { status: 404 }, + ); + } + /** * This is so we can just continue the request if the above fetch fails, * since the static asset might not exist, and we want to avoid Deno APIs @@ -64,6 +73,7 @@ export const serveStatic = (options: ServeStaticOptions = { root: "" }) => { * TODO: Maybe we should handle the type of error that fetch would throw? */ log.debug(`Static file: ${path} does not exist, continuing`); + await next(); } };