85b9ed5eb8
Provides a `revalidateReason` argument to `getStaticProps` ("stale" | "on-demand" | "build"). - Build indicates it was run at build time - On-demand indicates it was run as a side effect of [on-demand revalidation](https://nextjs.org/docs/pages/building-your-application/data-fetching/incremental-static-regeneration#on-demand-revalidation) - Stale indicates the resource was considered stale (either due to being in dev mode, or an expired revalidate period) This will allow changing behavior based on the context in which it's called. Closes NEXT-1900
15 lines
360 B
TypeScript
15 lines
360 B
TypeScript
import { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse<{ revalidated: boolean }>
|
|
) {
|
|
try {
|
|
await res.revalidate('/')
|
|
return res.json({ revalidated: true })
|
|
} catch (err) {
|
|
console.error('Failed to revalidate:', err)
|
|
}
|
|
|
|
res.json({ revalidated: false })
|
|
}
|