forked from deployd/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.js
32 lines (25 loc) · 754 Bytes
/
hook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* handles POST from github and restarts
*/
require('shelljs/global');
var allowed = ['207.97.227.253', '50.57.128.197', '108.171.174.178'];
var http = require('http');
http.createServer(function (req, res) {
var output = '';
var ip = req.socket.remoteAddress;
if(allowed.indexOf(ip) === -1) {
console.error('unkown ip trying hook! ' + ip);
res.statusCode = 401;
res.end('not allowed');
return;
}
if(req.url === '/hook') {
output += exec('git stash').output;
output += exec('git pull origin master').output;
output += exec('forever restart start.js').output;
console.log('restarting docs.deployd.com %s', new Date().toString());
console.log(output);
}
res.end(output);
})
.listen(3000);