From 48ba4679a9d22bc036de6cedada27e60ef4b981d Mon Sep 17 00:00:00 2001 From: Bad Manners Date: Fri, 5 Apr 2024 00:25:21 -0300 Subject: [PATCH] fix: serve local assets in development server Closes #75 --- packages/astro-pagefind/src/pagefind.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/astro-pagefind/src/pagefind.ts b/packages/astro-pagefind/src/pagefind.ts index d0be62c..ae7d3af 100644 --- a/packages/astro-pagefind/src/pagefind.ts +++ b/packages/astro-pagefind/src/pagefind.ts @@ -5,6 +5,7 @@ import sirv from "sirv"; export default function pagefind(): AstroIntegration { let outDir: string; + let assets: string | null; return { name: "pagefind", hooks: { @@ -25,6 +26,11 @@ export default function pagefind(): AstroIntegration { } else { outDir = fileURLToPath(config.outDir); } + if (config.build.assetsPrefix) { + assets = null; + } else { + assets = config.build.assets; + } }, "astro:server:setup": ({ server, logger }) => { if (!outDir) { @@ -39,7 +45,7 @@ export default function pagefind(): AstroIntegration { etag: true, }); server.middlewares.use((req, res, next) => { - if (req.url?.startsWith("/pagefind/")) { + if (req.url?.startsWith("/pagefind/") || (assets && req.url?.startsWith(`/${assets}/`))) { serve(req, res, next); } else { next();