Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#292 serve build: return 404 on missing .map requests instead of try to render as HTML #294

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/middleware/serveStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
};
Expand Down