使用Facebook Sharing Debugger获取网站会导致错误

问题描述 投票:0回答:1

我这两天一直在揪头发,想弄明白为什么Facebook Sharing Debugger不能正常获取我的next.js网站。这个网站是托管在Vercel上的。

当我用Postman或浏览器获取它时,没有任何错误(在Vercel日志和控制台)。服务器返回HTML和状态码200。然而,当我用facebook共享调试器获取它时。看看我们的刮刮卡看到的你的URL到底是什么样的 我得到了这个。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>
<body><p>An error occurred with this application.

NO_STATUS_CODE_FROM_FUNCTION
</p></body>
</html>

响应代码是502

Vercel控制台显示了这个错误。

[GET] /
23:19:43:38
Status:
-1
Duration:
2881.85ms
Memory Used:
54 MB
ID:
jkth8-1589318383376-c2fb8a7f81a0
User Agent:
facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
2020-05-12T21:19:46.290Z    a0145e40-064f-4313-9d63-068d4fd882c7    WARN    the options [servers] is not supported
2020-05-12T21:19:46.290Z    a0145e40-064f-4313-9d63-068d4fd882c7    WARN    the options [caseTranslate] is not supported
2020-05-12T21:19:46.290Z    a0145e40-064f-4313-9d63-068d4fd882c7    WARN    the options [dbName] is not supported
2020-05-12T21:19:46.290Z    a0145e40-064f-4313-9d63-068d4fd882c7    WARN    the options [srvHost] is not supported
2020-05-12T21:19:46.290Z    a0145e40-064f-4313-9d63-068d4fd882c7    WARN    the options [credentials] is not supported
2020-05-12T21:19:46.291Z    a0145e40-064f-4313-9d63-068d4fd882c7    ERROR   Uncaught Exception  {"errorType":"Error","errorMessage":"ENOENT: no such file or directory, open './public/fact-title-img-8bf01afa.jpeg'","code":"ENOENT","errno":-2,"syscall":"open","path":"./public/fact-title-img-8bf01afa.jpeg","stack":["Error: ENOENT: no such file or directory, open './public/fact-title-img-8bf01afa.jpeg'"]}
Unknown application error occurred

该错误与我的函数有关,该函数将从MongoDB获取的二进制数据保存为一个文件,在一个文件中。public 文件夹,所以我可以在一个反应组件中使用它。

这到底是怎么回事?为什么facebook的GET和Postman的GET工作方式不一样?

facebook facebook-like next.js vercel zeit
1个回答
0
投票

解决方法很简单。我在fs.writeFile回调中安全地返回了一个错误,而不是抛出它来终止进程。我不知道为什么只有在facebook获取网站的时候才会出现错误。

© www.soinside.com 2019 - 2024. All rights reserved.