Skip to content

Commit 2e84c5a

Browse files
committed
feat(site): Implement releases API to fetch GitHub releases with cache control
1 parent 2d8adea commit 2e84c5a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/app/api/releases/route.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { fetchGitHubReleases } from "@/lib/github";
2+
import { NextResponse, NextRequest } from "next/server";
3+
4+
export const revalidate = 86400; // Revalidate every 24 hours
5+
6+
export async function GET(request: NextRequest) {
7+
try {
8+
// Check if this is a cache-busting request from the client refresh button
9+
const url = new URL(request.url);
10+
const bypassCache =
11+
url.searchParams.has("t") ||
12+
request.headers.get("cache-control") === "no-cache" ||
13+
request.headers.get("pragma") === "no-cache";
14+
15+
const releases = await fetchGitHubReleases();
16+
17+
// If cache bypass requested, return with no-cache headers
18+
if (bypassCache) {
19+
return NextResponse.json(releases, {
20+
headers: {
21+
"Cache-Control": "no-cache, no-store, must-revalidate",
22+
Pragma: "no-cache",
23+
Expires: "0",
24+
"Content-Type": "application/json",
25+
},
26+
});
27+
}
28+
29+
// Otherwise use standard cache headers (24 hours)
30+
return NextResponse.json(releases, {
31+
headers: {
32+
"Cache-Control": "public, max-age=86400, s-maxage=86400", // 24 hours
33+
"Content-Type": "application/json",
34+
},
35+
});
36+
} catch (error) {
37+
console.error("Error in releases API:", error);
38+
return NextResponse.json(
39+
{ error: "Failed to fetch releases" },
40+
{ status: 500 },
41+
);
42+
}
43+
}

0 commit comments

Comments
 (0)