mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-12 06:06:37 +03:00
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>
20 lines
735 B
JavaScript
20 lines
735 B
JavaScript
import { join, dirname } from "path";
|
|
import { fileURLToPath } from "url";
|
|
import { readPatterns } from "../scripts/lib/utils.js";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
const PROJECT_ROOT = join(__dirname, "..");
|
|
|
|
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);
|
|
res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|