1 import { NextRequest, NextResponse } from "next/server"
2 import { getChangelogEntry } from "../../../../utils/changelog"
3 import {
4 PUBLIC_API_CACHE_CONTROL,
5 PUBLIC_API_CORS_HEADERS,
6 } from "../../../../utils/public-api"
7
8 const DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/
9
10 type Params = {
11 params: Promise<{ date: string }>
12 }
13
14 /**
15 * Returns a single Cloud changelog entry by its date, in the same shape as the
16 * entries of `/cloud/api/changelog`.
17 *
18 * @example
19 * GET /cloud/api/changelog/2026-08-10
20 */
21 export async function GET(req: NextRequest, { params }: Params) {
22 const { date } = await params
23
24 if (!DATE_REGEX.test(date)) {
25 return NextResponse.json(
26 { message: "The date must be in `YYYY-MM-DD` format." },
27 { status: 400, headers: PUBLIC_API_CORS_HEADERS }
28 )
29 }
30
31 const entry = await getChangelogEntry(
32 date,
33 process.env.NEXT_PUBLIC_BASE_URL || new URL(req.url).origin
34 )
35
36 if (!entry) {
37 return NextResponse.json(
38 { message: `No changelog entry was found for ${date}.` },
39 { status: 404, headers: PUBLIC_API_CORS_HEADERS }
40 )
41 }
42
43 return NextResponse.json(entry, {
44 headers: {
45 ...PUBLIC_API_CORS_HEADERS,
46 "Cache-Control": PUBLIC_API_CACHE_CONTROL,
47 },
48 })
49 }
50
51 export async function OPTIONS() {
52 return new NextResponse(null, {
53 status: 204,
54 headers: PUBLIC_API_CORS_HEADERS,
55 })
56 }