Created
August 16, 2011 22:49
-
-
Save j-mcnally/1150384 to your computer and use it in GitHub Desktop.
Beanstalk Deployment Hook Server
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
var http = require('http'); | |
var sys = require('sys') | |
var exec = require('child_process').exec; | |
http.createServer(function (req, res) { | |
var header=req.headers['authorization']||'', // get the header | |
token=header.split(/\s+/).pop()||'', // and the encoded auth token | |
auth=new Buffer(token, 'base64').toString(), // convert from base64 | |
parts=auth.split(/:/), // split on colon | |
username=parts[0], | |
password=parts[1]; | |
if (username != 'username' && password != 'password') { | |
res.writeHead(401, {'WWW-Authenticate': 'Basic realm="Secure Area"'}); | |
res.end('NO CHEEZBURGERZ 4 U'); | |
return; | |
} | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
child = exec("/usr/share/nodeHooker/hooker.sh", function (error, stdout, stderr) { | |
if (error !== null) { | |
} | |
else { | |
res.end('Deployment Hook Finished'); | |
} | |
}); | |
}).listen(6969, "0.0.0.0"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment