Skip to content

Commit

Permalink
fix: serve local assets in development server
Browse files Browse the repository at this point in the history
  • Loading branch information
BadMannersXYZ committed Apr 5, 2024
1 parent 99e6535 commit f3c9a29
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/astro-pagefind/src/pagefind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import sirv from "sirv";

export default function pagefind(): AstroIntegration {
let outDir: string;
let assets: string | null;
return {
name: "pagefind",
hooks: {
Expand All @@ -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) {
Expand All @@ -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();
Expand Down

0 comments on commit f3c9a29

Please sign in to comment.