在将Google的电子表格API与Vercel一起使用时发行
我正在Vercel上托管ExpressJS应用程序,在某个时候,它使用电子表格API存储生成的产品密钥。该功能看起来像这样:
async function addActivationCode(activationCode)
{
await googleSheets.spreadsheets.values.append({
auth: googleAuth,
spreadsheetId: sheetID,
range: "ActivationCodes!A:C",
valueInputOption: "USER_ENTERED",
resource: {
values: [
[activationCode, "1", "0"]
]
}
})
}
当本地托管时,此功能正常工作。但是在Vercel的实时日志中,我得到一个Fetcherror说:在建立安全TLS连接之前,客户网络套接字已断开。
调用此功能的try-catch块如下:
try
{
await addActivationCode(generateActivationCode())
}
catch(err)
{
console.log(err)
console.log("Failed to add new activation code.")
return
}
请注意,它不是将附加请求发送到电子表格API的唯一功能。还有另一个用于添加用户的功能,而且工作正常。在这里是:
async function addUser(username, password)
{
// Generate salt and hash the password in one command
const hashedPassword = await bcrypt.hash(password, 10)
// Add user to the Users sheet
await googleSheets.spreadsheets.values.append({
auth: googleAuth,
spreadsheetId: sheetID,
range: "Users!A2:B",
valueInputOption: "USER_ENTERED",
resource: {
values: [
[username, hashedPassword]
]
}
})
}
我找到了另一个
任何帮助都将受到赞赏。
I'm hosting an expressjs app on Vercel, at some point it uses the spreadsheet api to store a generated product key. The function looks like this:
async function addActivationCode(activationCode)
{
await googleSheets.spreadsheets.values.append({
auth: googleAuth,
spreadsheetId: sheetID,
range: "ActivationCodes!A:C",
valueInputOption: "USER_ENTERED",
resource: {
values: [
[activationCode, "1", "0"]
]
}
})
}
This function works perfectly fine when hosted locally. But in Vercel's Realtime logs I get a FetchError saying: Client network socket disconnected before secure TLS connection was established.
the try-catch block that calls this function is the following:
try
{
await addActivationCode(generateActivationCode())
}
catch(err)
{
console.log(err)
console.log("Failed to add new activation code.")
return
}
Note that it is not the only function that sends an append request to the spreadsheet api. There's another function used to add users and it's working fine. Here it is:
async function addUser(username, password)
{
// Generate salt and hash the password in one command
const hashedPassword = await bcrypt.hash(password, 10)
// Add user to the Users sheet
await googleSheets.spreadsheets.values.append({
auth: googleAuth,
spreadsheetId: sheetID,
range: "Users!A2:B",
valueInputOption: "USER_ENTERED",
resource: {
values: [
[username, hashedPassword]
]
}
})
}
I found another post talking about this issue but not in Vercel. It was related to proxies. My knowledge about proxies atm is limited so I didn't quite understand how to fix this in Vercel.
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现问题来自哪里。这是Vercel的 limits 。对于使用免费计划的用户,他们的应用程序不能花费10秒钟以上来响应请求。例如,我在应用程序中负责注册用户的功能做了5件事:
那是发送给电子表格API的5个该死的请求!这肯定需要花费的时间超过限制才能完成。
I found where the problem is coming from. It's Vercel's limits. For users using the free plan, their app can't take more than 10 seconds to respond to a request. For instance, the function I have in my app that's responsible for registering users does 5 things:
That's 5 god damn requests sent to the spreadsheet api! That definitely takes more time than the limit to complete.