'Internal Server Error' when previewing from headless CraftCMS / Next.js

Hey everyone! I’ll put as much detail as I can and thank you for anyone who helps me out :slight_smile:

The site name is https://unravelyourfood.netlify.app/ — I had headless preview working a while ago but after having had a delay in working on the site, when I try to preview using the headless url:
https://unravelyourfood.netlify.app/api it returns Internal Server Error.

I’ve tried running curl https://unravelyourfood.netlify.app/api from my local machine and it returns the same error.

Is this an issue with Netlify?

All the best,
Andrew

Just incase it helps to show, this is the content of my preview.js for my api route:

export default function handler(req, res) {
  if (req.query.token === null) {
    return res.status(401).json({ message: "No preview token" });
  }
  if (req.query.uri === null) {
    return res.status(401).json({ message: "No URI provided" });
  }
  res.setPreviewData(
    {
      token: req.query.token ?? null,
    },
    {
      maxAge: 60,
    }
  );
  res.redirect(`/${req.query.uri}`);
}

Thank you so much for this — it’s a shame we can’t use the latest version of Next.js but downgrading to 13.4.8 worked for me.