mirror of
https://hk.gh-proxy.com/https://github.com/NodeBB/docs.git
synced 2025-10-03 08:43:37 +08:00
44 lines
1.1 KiB
JavaScript
Executable file
44 lines
1.1 KiB
JavaScript
Executable file
#!/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);
|