-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
60 lines (50 loc) · 1.45 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
const bodyParser = require('body-parser');
const express = require('express');
const { bottender } = require('bottender');
const path = require('path');
const { authUrl, saveToken } = require('./src/GoogleOauth');
const ejs = require('ejs');
const app = bottender({
dev: process.env.NODE_ENV !== 'production',
});
const port = Number(process.env.PORT) || 5000;
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
server.use(express.static('public'));
server.use(
bodyParser.json({
verify: (req, _, buf) => {
req.rawBody = buf.toString();
},
})
);
server.get('/api', (req, res) => {
res.json({ ok: true });
});
server.get('/liff', (req, res) => {
console.log('liff');
const filename = path.join(__dirname + `/src/liff/settings.html`);
authUrl().then(url => {
ejs.renderFile(filename, { url }, {}, function(err, str) {
res.send(str);
});
});
return;
});
server.all('/webhooks/line', (req, res) => {
return handle(req, res);
});
server.all('/googleRedirect', async (req, res) => {
const filename = path.join(__dirname + `/src/page/googleRedirect.html`);
const code = req.query.code;
await saveToken(code);
ejs.renderFile(filename, {}, {}, function(err, str) {
res.send(str);
});
});
server.listen(port, err => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
});