Skip to content

Commit

Permalink
fix(examples/basic): update static file serving (#390)
Browse files Browse the repository at this point in the history
closes #389

Signed-off-by: Logan McAnsh <[email protected]>
  • Loading branch information
mcansh authored Aug 1, 2024
1 parent 87feccf commit dec8ebc
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions examples/basic/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ if (process.env.NODE_ENV === "production") {
root: PUBLIC_DIR,
prefix: "/",
wildcard: false,
cacheControl: true,
dotfiles: "allow",
etag: true,
serveDotFiles: true,
lastModified: true,
setHeaders,
});
} else
await app.register(fastifyStatic, {
root: BUILD_DIR,
prefix: "/build",
wildcard: true,
decorateReply: false,
cacheControl: true,
dotfiles: "allow",
Expand All @@ -69,17 +57,24 @@ if (process.env.NODE_ENV === "production") {
lastModified: true,
setHeaders,
});
}

await app.register(fastifyStatic, {
root: PUBLIC_DIR,
root: BUILD_DIR,
prefix: "/",
wildcard: false,
cacheControl: true,
dotfiles: "allow",
etag: true,
serveDotFiles: true,
lastModified: true,
setHeaders,
setHeaders(res, filepath) {
let isAsset = filepath.startsWith(BUILD_DIR);
res.setHeader(
"cache-control",
isAsset ? ASSET_CACHE_CONTROL : DEFAULT_CACHE_CONTROL,
);
},
});

app.register(async function (childServer) {
Expand Down

0 comments on commit dec8ebc

Please sign in to comment.