-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
65 lines (49 loc) · 1.64 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require('dotenv').config();
const bodyParser = require('body-parser');
const express = require('express');
const { bottender } = require('bottender');
// const { notificacaoCron } = require('./notification');
// const handler = require('./index');
// const HangoutContext = require('./hangouts');
// if (notificacaoCron.running) console.log(`Crontab notificacaoCron is running? => ${notificacaoCron.running}`);
const requests = require('./requests');
const app = bottender({ dev: true });
const port = Number(process.env.API_PORT) || 5000;
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
server.use(bodyParser.urlencoded({ extended: false }));
server.use(
bodyParser.json({
verify: (req, _, buf) => {
req.rawBody = buf.toString();
},
}),
);
server.get('/api', (req, res) => {
res.json({ ok: true });
});
server.post('/add-label', async (req, res) => {
await requests.addLabel(req, res);
});
server.get('/name-id', async (req, res) => {
await requests.getNameFBID(req, res);
});
// server.post('/hangouts', async (req, res) => {
// await res.sendStatus(200);
// const { body } = req;
// // console.log('body', JSON.stringify(body, null, 2));
// const hangouts = new HangoutContext(body);
// await hangouts.build();
// await handler(hangouts);
// });
server.all('*', (req, res) => { // eslint-disable-line
return handle(req, res);
});
server.listen(port, (err) => {
if (err) throw err;
console.log(`Server is running on ${port} port...`);
console.log(`App: ${process.env.APP} & Page: ${process.env.PAGE}`);
console.log(`MA User: ${process.env.MA_USER}`);
});
});