Skip to content

Instantly share code, notes, and snippets.

@tetrashine
Last active July 18, 2020 11:37
Show Gist options
  • Save tetrashine/0c87e9353a3fef4e1f69c9d7427209c7 to your computer and use it in GitHub Desktop.
Save tetrashine/0c87e9353a3fef4e1f69c9d7427209c7 to your computer and use it in GitHub Desktop.
captcha-backend.js
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