Disable cache storage on live JSON routes
This commit is contained in:
18
src/lib/api-response.ts
Normal file
18
src/lib/api-response.ts
Normal 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 ?? {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user