Showing
1 changed file
with
37 additions
and
0 deletions
Experiments/messenger/webhook/test.js
0 → 100644
1 | +var express = require('express'); | ||
2 | +const bodyParser = require('body-parser'); | ||
3 | +var app = express(); | ||
4 | +const fs = require('fs'); | ||
5 | +const path = require('path'); | ||
6 | +const HTTPS = require('https'); | ||
7 | +const domain = "2019102226.osschatbot2022.ml" | ||
8 | +const sslport = 23023; | ||
9 | + | ||
10 | +app.use(bodyParser.json()); | ||
11 | + | ||
12 | +app.post('/hook', function (request, response) { | ||
13 | + | ||
14 | + var eventObj = request.body.events[0]; | ||
15 | + | ||
16 | + // request log | ||
17 | + console.log('======================', new Date(), '======================'); | ||
18 | + | ||
19 | + response.sendStatus(200); | ||
20 | +}); | ||
21 | + | ||
22 | + | ||
23 | +try { | ||
24 | + const option = { | ||
25 | + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'), | ||
26 | + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(), | ||
27 | + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(), | ||
28 | + }; | ||
29 | + | ||
30 | + HTTPS.createServer(option, app).listen(sslport, () => { | ||
31 | + console.log(`[HTTPS] Server is started on port ${sslport}`); | ||
32 | + }); | ||
33 | +} catch (error) { | ||
34 | + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | ||
35 | + console.log(error); | ||
36 | +} | ||
37 | + |
-
Please register or login to post a comment