Since 12.1.0 it is possible the On-demand Revalidation.
https://nextjs.org/docs/basic-features/data-fetching/incremental-static-regeneration
Sending array of programIds, how can I invalidate array of slugs? I tried this:
export default async function handler(req, res) {
// Check for secret to confirm this is a valid request
if (req.query.secret !== process.env.NEXT_PUBLIC_SECRET_TOKEN) {
return res.status(401).json({ message: 'Invalid token' })
}
try {
const programIds: String[] = req.query.programId
programIds.map((programId) =>
await res.unstable_revalidate(`/hu/buyTicket/${programId}`)
)
return res.json({ revalidated: true })
} catch (err) {
// If there was an error, Next.js will continue
// to show the last successfully generated page
return res.status(500).send('Error revalidating')
}
}
I got this error:
'await' expressions are only allowed within async functions and at the top levels of modules.