// simple example for testing it manually from your browser.exportdefaultfunctionhandler(req, res) {res.setDraftMode({ enable:true })res.end('Draft mode is enabled')}
exportdefaultasync (req, res) => {// Check the secret and next parameters// This secret should only be known to this API route and the CMSif (req.query.secret !=='MY_SECRET_TOKEN'||!req.query.slug) {returnres.status(401).json({ message:'Invalid token' }) }// Fetch the headless CMS to check if the provided `slug` exists// getPostBySlug would implement the required fetching logic to the headless CMSconstpost=awaitgetPostBySlug(req.query.slug)// If the slug doesn't exist prevent draft mode from being enabledif (!post) {returnres.status(401).json({ message:'Invalid slug' }) }// Enable Draft Mode by setting the cookieres.setDraftMode({ enable:true })// Redirect to the path from the fetched post// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilitiesres.redirect(post.slug)}