From 8a88163f6f36860c9f813867ff00a2cec94908ed Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 1 Nov 2023 23:38:32 -0400 Subject: [PATCH] fix: nop if we aren't in development --- src/pages/sw.js.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pages/sw.js.ts b/src/pages/sw.js.ts index 9a81e24..34effe0 100644 --- a/src/pages/sw.js.ts +++ b/src/pages/sw.js.ts @@ -2,8 +2,14 @@ import type { APIRoute } from "astro"; import * as fs from "node:fs"; import * as path from "node:path"; -export const GET: APIRoute = ({params, request}) => { - const filePath = path.resolve(process.cwd(), "dist/sw.js"); - const fileContents = fs.readFileSync(filePath); - return new Response(fileContents, { status: 200, headers: { 'Content-Type': 'application/javascript' } }); -} \ No newline at end of file +export const GET: APIRoute = ({ params, request }) => { + if (process.env.MODE !== "development") { + return new Response(); + } + const filePath = path.resolve(process.cwd(), "dist/sw.js"); + const fileContents = fs.readFileSync(filePath); + return new Response(fileContents, { + status: 200, + headers: { "Content-Type": "application/javascript" }, + }); +};