Last active
July 18, 2020 11:37
-
-
Save tetrashine/0c87e9353a3fef4e1f69c9d7427209c7 to your computer and use it in GitHub Desktop.
captcha-backend.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const captchaToken = req.body.token; | |
const data = querystring.stringify({ | |
secret: fullConfig.CAPTCHA_SECRET, | |
response: captchaToken | |
}); | |
const verifiedHuman = await (new Promise((resolve, reject) => { | |
const options = { | |
hostname: 'www.google.com', | |
path: '/recaptcha/api/siteverify', | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Content-Length': Buffer.byteLength(data) | |
} | |
}; | |
const req = http.request(options, (response) => { | |
response.on('data', (chunk) => { | |
const resJson = JSON.parse(chunk.toString()); | |
resolve(resJson.success); | |
}); | |
}); | |
req.write(data); | |
})) | |
if (verifiedHuman) { | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment