Skip to content

Commit fcea7e1

Browse files
committed
chore: stale-while-revalidate headers for changelog
1 parent 7c34319 commit fcea7e1

1 file changed

Lines changed: 36 additions & 14 deletions

File tree

packages/console/app/src/routes/changelog.json.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ type HighlightGroup = {
2020
items: HighlightItem[]
2121
}
2222

23+
const ok = "public, max-age=1, s-maxage=300, stale-while-revalidate=86400, stale-if-error=86400"
24+
const error = "public, max-age=1, s-maxage=60, stale-while-revalidate=600, stale-if-error=86400"
25+
2326
function parseHighlights(body: string): HighlightGroup[] {
2427
const groups = new Map<string, HighlightItem[]>()
2528
const regex = /<highlight\s+source="([^"]+)">([\s\S]*?)<\/highlight>/g
@@ -90,25 +93,44 @@ export async function GET() {
9093
Accept: "application/vnd.github.v3+json",
9194
"User-Agent": "OpenCode-Console",
9295
},
93-
})
96+
cf: {
97+
// best-effort edge caching (ignored outside Cloudflare)
98+
cacheTtl: 60 * 5,
99+
cacheEverything: true,
100+
},
101+
} as any)
94102

95103
if (!response.ok) {
96-
return { releases: [] }
104+
return new Response(JSON.stringify({ releases: [] }), {
105+
status: 503,
106+
headers: {
107+
"Content-Type": "application/json",
108+
"Cache-Control": error,
109+
},
110+
})
97111
}
98112

99113
const releases = (await response.json()) as Release[]
100114

101-
return {
102-
releases: releases.map((release) => {
103-
const parsed = parseMarkdown(release.body || "")
104-
return {
105-
tag: release.tag_name,
106-
name: release.name,
107-
date: release.published_at,
108-
url: release.html_url,
109-
highlights: parsed.highlights,
110-
sections: parsed.sections,
111-
}
115+
return new Response(
116+
JSON.stringify({
117+
releases: releases.map((release) => {
118+
const parsed = parseMarkdown(release.body || "")
119+
return {
120+
tag: release.tag_name,
121+
name: release.name,
122+
date: release.published_at,
123+
url: release.html_url,
124+
highlights: parsed.highlights,
125+
sections: parsed.sections,
126+
}
127+
}),
112128
}),
113-
}
129+
{
130+
headers: {
131+
"Content-Type": "application/json",
132+
"Cache-Control": ok,
133+
},
134+
},
135+
)
114136
}

0 commit comments

Comments
 (0)