-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (37 loc) · 1.04 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
const bodyParser = require('body-parser');
const express = require('express');
const { bottender } = require('bottender');
const app = bottender({
dev: process.env.NODE_ENV !== 'production',
});
const port = Number(process.env.PORT) || 8000;
// The request handler of bottender
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
server.use(
bodyParser.json({
verify: (req, _, buf) => {
req.rawBody = buf.toString();
},
})
);
// Custom route
server.get('/api', (req, res) => {
res.json({ ok: true });
});
// Route for webhook request
server.all('*', (req, res) => {
return handle(req, res);
});
server.listen(port, (err) => {
if (err) throw err;
console.log(`Running on http://localhost:${port}`);
});
// For URL Shortener
const connectDB = require('./config/db');
connectDB();
server.use(express.json({ extended: false }));
// server.use('/', require('./src/index'));
// server.use('/api/url', require('./src/url_shortener'));
});