Formspree Webhook Example
require("isomorphic-fetch")
exports.endpoint = function(req, res) {
let url = req.url;
if (url === '/hook') {
// Step 1: Confirm the subscription this request
// includes an X-Hook-Secret
let hook_secret = req.headers["x-hook-secret"]
if (hook_secret) {
res.setHeader("x-hook-secret", hook_secret)
res.end();
} else {
// Step 1: Confirm the subscription this request
// includes an X-Hook-Secret
console.log("Received webhook!")
// This is a webhook!
fetch("cc2742b8.ngrok.com")
res.end()
}
} else {
res.end(url + "\n");
}
}
no comments