-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (31 loc) · 969 Bytes
/
server.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
33
34
35
36
37
38
39
40
41
42
/* global process */
import {telegramBotApi} from './lib';
import express from 'express';
import bodyParser from 'body-parser';
import {handlers} from './handlers';
import morgan from 'morgan';
const port = process.env.PORT;
const token = process.env.BOT_TOKEN;
const app = express();
app.use(morgan('tiny'));
app.use(bodyParser.json());
app.post('/redeploy', (req, res) => {
console.log('git hook arrived', req.body);
const exec = require('child_process').exec;
exec('git pull && npm i', (error, stdout, stderr) => {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
return res.status(500).send(error);
}
res.sendStatus(200);
});
});
app.post(`/${token}`, handlers);
app.all('*', (req, res) => {
res.send(`I'm bot`);
});
app.listen(port, () => {
console.log(`Server started at ${port}`);
});