You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
import{getPageData}from"utils/api"import{parseCookies}from"utils/parse-cookies"constpreview=async(req,res)=>{// Check the secret and next parameters// This secret should only be known to this API route and the CMSif(req.query.secret!==(process.env.PREVIEW_SECRET||"secret-token")){returnres.status(401).json({message: "Invalid token"})}constcookies=parseCookies(req)constslugArray=req.query.slug.split("/")constlocaleID=req.query.locale||"en"// Fetch the headless CMS to check if the provided `slug` existsconstpageData=awaitgetPageData({locale: localeID,slug: slugArray.join("/"),preview: true,})// If the slug doesn't exist prevent preview mode from being enabledif(!pageData){returnres.status(401).json({message: "Invalid slug"})}// Enable Preview Mode by setting the cookiesres.setPreviewData({})// Redirect to the path from the fetched post// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities// Prefix with locale so previews are available in all languagesres.writeHead(307,{Location: `/${pageData.attributes.locale}/${pageData.attributes.slug}`,})res.end()}exportdefaultpreview// You can view Preview pages with URLs like this:// http://localhost:3000/api/preview?secret=<preview-secret>&slug=<slug>// where <preview-secret> is the secret token defined in your .env config// and where <slug> is the slug you entered in Strapi for your page// The slug must match the current locale
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I set this starter project up locally with no customization, and I'm having issues getting preview mode to work. I get this error:
Has anyone else encountered this? Is the localization plugin compatible with preview mode?
I tried to add a parameter to my preview url but it had no effect:
Windows 11
Node.js v14.18.3
The text was updated successfully, but these errors were encountered: