mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
00d3c8307d
### What? When doing an On Demand revalidation (with `res.revalidate` or using `x-prerender-revalidate` header ), `use cache` entry will never get revalidated ### Why? It should behave the same as the fetch cache or `unstable_cache` ### How? We force revalidation of `use cache` entry when doing an on demand revalidation --------- Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
23 lines
579 B
TypeScript
23 lines
579 B
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
const pathParam = req.query['path']
|
|
|
|
if (!pathParam) {
|
|
return res.status(400).send(`Missing required query param "path"`)
|
|
}
|
|
|
|
const paths = Array.isArray(pathParam) ? pathParam : [pathParam]
|
|
|
|
try {
|
|
await Promise.all(paths.map((path) => res.revalidate(path)))
|
|
return res.json({ revalidated: true })
|
|
} catch (err) {
|
|
console.error(err)
|
|
return res.status(500).send(`Error revalidating ${paths}`)
|
|
}
|
|
}
|