platforms
platforms copied to clipboard
Revalidation doesn't work when hosted on Vercel
Hello, everybody!
Well, I have a NextJS project which contains the following code in api/revalidate:
export default async function handler(req, res) {
if (req.query.secret !== process.env.SECRET_TOKEN) {
return res.status(401).json({ message: 'Invalid token' })
}
try {
await res.revalidate('/blog/g_pro_wireless')
return res.json({ revalidated: true })
} catch (err) {
return res.status(500).send('Error revalidating')
}
}
When I do http://my_perfect_website.com/api/revalidate?secret=the_token in the hosted production version, nothing works; however, if I do http://localhost:3000/api/revalidate?secret=the_token after doing yarn run build and yarn run start, everything works. Evidently, the problem appears once I have deployed the app to Vercel. What can I do?
By the way, if I remove the token validation, it merely shows Error validating in the hosted production version, whereas both with the token and without everything works perfectly in the non-hosted production version.
Also, I have a free domain.
Also seeing this. I think it is to do with Middleware caching - if I go to the sites (not via subdomain, ie /_sites/test) it works for me
Hey! This should be fixed now with the https://github.com/vercel/platforms/pull/221 migration complete since we moved to using revalidateTag inside Server Actions (no need for secret tokens 