我正在使用 next.js 呈现来自 sanity.io 的数据,并将其部署为 AWS 上的无服务器应用程序(边缘优化)。起初这个功能是有效的,但在某些时候它只是停止了在 aws 部署上的工作,我无法弄清楚它是什么。在 http://localhost:3000 端点上它仍在工作。
我使用了官方的 next.js 指南来实现 https://nextjs.org/docs/advanced-features/preview-mode
这是代码的简单版本
export default async function handler(req, res) {
// code that checks that that the request is correct here, it works
console.log('about to call setPreviewData', res.setPreviewData.toString());
// the previous log command is called and this is how the function is logged
// (data,options= {} )=>setPreviewData(apiRes,data,Object.assign({} apiContext,options))
res.setPreviewData({})
// the function crashes between the previous and this log
console.log('Location to go to', `/${req.query.slug}`)
res.writeHead(307, {
Location: `/${post.type}/${post.slug}`
})
res.end()
}
相关依赖
"next": "^10.0.3",
开发依赖
"serverless-next.js": "^1.15.0-alpha.2",
"serverless-nextjs-plugin": "^2.5.2-alpha.0"
更奇怪的是,在同一个 api 文件夹中,我有一个退出预览功能
export default async function handler(_, res) {
res.clearPreviewData()
res.writeHead(307, { Location: '/' })
res.end()
}
我检查了 CloudFront 配置并打开了“转发 Cookie”。
在 Cloudwatch 中,我得到一连串关于 e[t] is not a function 的错误
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "TypeError: e[t] is not a function",
"reason": {
"errorType": "TypeError",
"errorMessage": "e[t] is not a function",
"stack": [
"TypeError: e[t] is not a function",
" at __webpack_require__ (/var/task/pages/api/previewArticle.js:7249:30130)"
...
有人对我可以尝试什么有任何建议吗?谢谢 :)