-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (36 loc) · 1.06 KB
/
index.js
File metadata and controls
40 lines (36 loc) · 1.06 KB
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
require('dotenv').config();
const { exec } = require('child_process');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const PORT = process.env.WEBHOOK_PORT;
let rebuilding = false;
app.use(bodyParser.json());
app.post(`/hook/:path`, (req, res) => {
if (req.params.path !== process.env.WEBHOOK_PATH) {
return;
}
if (process.env.TESTING !== false) {
if (!rebuilding) {
rebuilding = true;
exec(process.env.SHELL_SCRIPT, (error, stdout, stderr) => {
if (error) {
console.error(JSON.stringify(error));
return;
}
if (stderr) {
console.error(JSON.stringify(stderr));
return;
}
console.log(JSON.stringify(stdout));
rebuilding = false;
});
res.status(200).send({ message: 'Rebuild started' });
} else {
res.status(200).send({ message: 'Rebuilding' });
}
} else {
res.status(200).send({ message: 'Testing' });
}
});
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));