Skip to content
Merged
Changes from 5 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
12 changes: 10 additions & 2 deletions packages/fern-docs/bundle/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ export const middleware: NextMiddleware = async (request) => {
rewritePath,
reason: "Self-hosted mode - using static route"
});
return rewrite(rewritePath);
const response = rewrite(rewritePath);
// Set CDN cache headers for static pages: no browser cache, 7 min CDN cache + 1 day stale-while-revalidate
response.headers.set("Cache-Control", "public, max-age=1, s-maxage=1, stale-while-revalidate=120");
response.headers.set("CDN-Cache-Control", "max-age=1, stale-while-revalidate=120");
return response;
}

const { getAuthState } = await createGetAuthStateEdge(request, (token) => {
Expand All @@ -342,7 +346,11 @@ export const middleware: NextMiddleware = async (request) => {
return rewrite(withDomain(`/dynamic/${encodeURIComponent(conformTrailingSlash(pathname))}`));
}

return rewrite(withDomain(`/static/${encodeURIComponent(conformTrailingSlash(pathname))}`));
const response = rewrite(withDomain(`/static/${encodeURIComponent(conformTrailingSlash(pathname))}`));
response.headers.set("Cache-Control", "public, max-age=1, s-maxage=1, stale-while-revalidate=120");
response.headers.set("CDN-Cache-Control", "max-age=1, stale-while-revalidate=120");
response.headers.set("Vercel-CDN-Cache-Control", "max-age=86400, stale-while-revalidate=120");
return response;
};

const response = getResponse();
Expand Down
Loading