const functions = require('firebase-functions');
const express = require('express')
const request = require('request')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.post('/reserver', (req, res) => {
if(req.body.captcha === undefined || req.body.captcha === '' || req.body.captcha === null) {
return res.json({"success": false, "msg": "Bekræft venligst captcha"})
}
const secretKey = 'SECRET-KEY'
const verifyURL = `https://www.google.com/recaptcha/api/siteverify?secret=${secretKey}&response=${req.body.captcha}`
request(verifyURL, (err, response, body) => {
body = JSON.parse(body)
if(body.success != undefined && !body.success) {
return res.json({"success": false, "msg": "Failed captcha verify"})
}
return res.json({"success": true, "msg": "Godkendt captcha"})
})
})
exports.app = functions.https.onRequest(app)
我正在尝试将Recaptcha集成到我的网站上。我正在使用Firebase Cloud函数验证验证码。 “ app”函数的第一部分,即if语句,运行得很好。但是,当我完成Recaptcha时,因此继续请求(verifyURL,(err,response,body),它给我2个错误。“ POST 500”和“ Uncaught(promise)SyntaxError:JSON位置0处的意外令牌E” “。感谢您的帮助。