Disable cache storage on live JSON routes

This commit is contained in:
kris
2026-04-07 13:42:46 +08:00
parent 6153e94000
commit cc1afe8173
8 changed files with 150 additions and 19 deletions

18
src/lib/api-response.ts Normal file
View File

@@ -0,0 +1,18 @@
import { NextResponse } from "next/server";
export const NO_STORE_JSON_HEADERS = {
"Cache-Control": "private, no-store, max-age=0",
} as const;
export function jsonNoStore(
body: Parameters<typeof NextResponse.json>[0],
init?: Parameters<typeof NextResponse.json>[1],
) {
return NextResponse.json(body, {
...init,
headers: {
...NO_STORE_JSON_HEADERS,
...(init?.headers ?? {}),
},
});
}