mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
71dbb45ca8
* fix(pages): pin revalidate loopback origin * test(pages): cover production revalidation origin * fix(pages): preserve internal revalidation boundaries * fix(pages): preserve on-demand revalidation boundaries * fix(pages): dispatch Worker revalidation internally * fix(pages): authenticate revalidation request context * fix(pages): isolate revalidation transport headers * test(pages): account for generated route table size * fix(pages): align on-demand revalidation semantics * fix(pages): align revalidation response cache parity * fix(pages): preserve regenerated ISR representations * fix(pages): align ISR cache representations * fix(pages): preserve canonical ISR representations * fix(pages): align cached response parity * fix(pages): preserve custom App render props * fix(pages): preserve optional App page props * fix(pages): preserve optional App props on the client * fix(pages): normalize client App page props * fix(pages): preserve App data merge semantics * fix(pages): keep redirect status helper internal * fix(pages): match Next.js terminal ISR behavior * fix(pages): preserve custom app error envelopes * fix(pages): match Next.js dev revalidation semantics * test(pages): align dev revalidation parity coverage * chore(pages): remove stale cache helper exports * fix(cache): preserve explicit no-store context
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from "next";
|
|
import {
|
|
installCustomRevalidateCache,
|
|
restoreCustomRevalidateCache,
|
|
} from "../../custom-revalidate-cache";
|
|
|
|
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
const kind = Array.isArray(req.query.kind) ? req.query.kind[0] : req.query.kind;
|
|
if (kind === "restore") {
|
|
restoreCustomRevalidateCache();
|
|
res.json({ restored: true });
|
|
return;
|
|
}
|
|
|
|
if (kind === "redirect") {
|
|
installCustomRevalidateCache({
|
|
kind: "REDIRECT",
|
|
props: {
|
|
pageProps: {
|
|
__N_REDIRECT: "/about",
|
|
__N_REDIRECT_STATUS: 308,
|
|
__N_REDIRECT_BASE_PATH: false,
|
|
},
|
|
},
|
|
});
|
|
} else if (kind === "notFound") {
|
|
installCustomRevalidateCache(null);
|
|
} else if (kind === "legacyRedirect") {
|
|
installCustomRevalidateCache({
|
|
kind: "PAGES",
|
|
html: "",
|
|
pageData: {},
|
|
headers: { Location: "/about" },
|
|
status: 307,
|
|
});
|
|
} else if (kind === "legacyNotFound") {
|
|
installCustomRevalidateCache({
|
|
kind: "PAGES",
|
|
html: "",
|
|
pageData: {},
|
|
headers: undefined,
|
|
status: 404,
|
|
});
|
|
} else {
|
|
res.status(400).json({ installed: false });
|
|
return;
|
|
}
|
|
res.json({ installed: true, kind });
|
|
}
|