Skip to content

Instantly share code, notes, and snippets.

@grantglidewell
Created February 19, 2020 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantglidewell/36a2c9e709aa51890d19911a2ca78b4d to your computer and use it in GitHub Desktop.
Save grantglidewell/36a2c9e709aa51890d19911a2ca78b4d to your computer and use it in GitHub Desktop.
const fetch = require("node-fetch");
const WEBHOOK_URL = "WEBHOOK_FROM_NETLIFY";
const authUsers = ["USER_ID_FROM_SLACK"];
module.exports = async (req, res) => {
const { body } = req;
if (authUsers.includes(body.user_id)) {
// send the webhook
const webhookRequest = await fetch(WEBHOOK_URL, { method: "POST" });
if (webhookRequest.statusText === "OK") {
res.json(
"Successfully sent the build command, changes should be reflected on the live site in about 45 min."
);
} else {
res.json(
`There was a problem sending the build command ${webhookRequest}`
);
}
} else {
res.json(
`You aren't authorized to send the build command, contact the administrator of this command, give them this id: ${body.user_id}`
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment