Add edge cache headers to all API routes to reduce Vercel function invocations

All API routes serve static content that only changes at deploy time, but had
0% cache hit rate. Adding s-maxage=86400 lets Vercel's CDN cache responses at
the edge, which should take the ~28K daily API requests from 0% to ~99% cache.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Paul Bakaus
2026-03-08 17:10:04 -07:00
co-authored by Claude Opus 4.6
parent a9c66c4cda
commit 98d16686dc
6 changed files with 6 additions and 0 deletions
+1
View File
@@ -23,6 +23,7 @@ export default function handler(req, res) {
}
const content = readFileSync(commandPath, "utf-8");
res.setHeader("Cache-Control", "public, s-maxage=86400, stale-while-revalidate=3600");
res.status(200).json({ content });
} catch (error) {
console.error("Error in /api/command-source:", error);
+1
View File
@@ -39,6 +39,7 @@ export default function handler(req, res) {
}
}
res.setHeader("Cache-Control", "public, s-maxage=86400, stale-while-revalidate=3600");
res.status(200).json(commands);
} catch (error) {
console.error("Error in /api/commands:", error);
+1
View File
@@ -62,6 +62,7 @@ export default function handler(req, res) {
const content = readFileSync(filePath);
const fileName = basename(filePath).replace(/[^a-zA-Z0-9._-]/g, '');
res.setHeader("Cache-Control", "public, s-maxage=86400, stale-while-revalidate=3600");
res.setHeader("Content-Type", "application/octet-stream");
res.setHeader("Content-Disposition", `attachment; filename="${fileName}"`);
res.send(content);
+1
View File
@@ -26,6 +26,7 @@ export default function handler(req, res) {
}
const content = readFileSync(zipPath);
res.setHeader("Cache-Control", "public, s-maxage=86400, stale-while-revalidate=3600");
res.setHeader("Content-Type", "application/zip");
const safeProvider = provider.replace(/[^a-zA-Z0-9._-]/g, '');
res.setHeader("Content-Disposition", `attachment; filename="impeccable-style-${safeProvider}.zip"`);
+1
View File
@@ -10,6 +10,7 @@ export default function handler(req, res) {
try {
// Extract patterns from SKILL.md using the shared utility
const { patterns, antipatterns } = readPatterns(PROJECT_ROOT);
res.setHeader("Cache-Control", "public, s-maxage=86400, stale-while-revalidate=3600");
res.status(200).json({ patterns, antipatterns });
} catch (error) {
console.error("Error in /api/patterns:", error);
+1
View File
@@ -36,6 +36,7 @@ export default function handler(req, res) {
}
}
res.setHeader("Cache-Control", "public, s-maxage=86400, stale-while-revalidate=3600");
res.status(200).json(skills);
} catch (error) {
console.error("Error in /api/skills:", error);