-
Notifications
You must be signed in to change notification settings - Fork 47
/
daemon
executable file
·44 lines (34 loc) · 1.12 KB
/
daemon
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
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
'use strict';
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');
const execFile = require('child_process').execFile;
const async = require('async');
const app = express();
app.use(bodyParser.json({
verify: function (req, res, buf, encoding) {
let hash = crypto.createHmac('sha1', process.env.SECRET);
hash.update(buf);
let digest = hash.digest('hex');
res.locals.verified = String('sha1=' + digest) === req.headers['x-hub-signature'];
}
}));
app.post('/github', function (req, res) {
var headers = req.headers;
let shasum = crypto.createHash('sha1');
// Basic sanity checks
if (!req.body || req.headers['x-github-event'] !== 'push' || !res.locals.verified) {
return res.sendStatus(400);
}
execFile('/bin/bash', [path.join(__dirname, 'build.sh')], function (err) {
res.sendStatus(err ? 500 : 200);
if (err) {
console.error('Docs build failed @ ' + new Date().toISOString(), err.stack);
} else {
console.log('Docs build completed @ ' + new Date().toISOString());
}
});
});
app.listen(8001);