Created
July 11, 2023 08:25
-
-
Save popeating/208bcb78083b35513dcccec4ad67acf7 to your computer and use it in GitHub Desktop.
webhook
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 secret = "very_secret_key"; | |
const repo = "/var/www/example.com"; | |
const http = require('http'); | |
const crypto = require('crypto'); | |
const exec = require('child_process').exec; | |
const BUILD_CMD = 'npm install && NODE_ENV=production npm run build'; | |
const PM2_CMD = 'pm2 restart <NODE APP NAME>'; | |
http.createServer(function (req, res) { | |
req.on('data', function(chunk) { | |
let sig = "sha1=" + crypto.createHmac('sha1', secret).update(chunk.toString()).digest('hex'); | |
if (req.headers['x-hub-signature'] == sig) { | |
exec('cd ' + repo + ` && git pull && npm install && ${BUILD_CMD} && ${PM2_CMD}`); | |
} | |
}); | |
res.end(); | |
}).listen(8200); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment