Created
February 19, 2020 17:35
-
-
Save grantglidewell/36a2c9e709aa51890d19911a2ca78b4d to your computer and use it in GitHub Desktop.
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 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