김시환

update app.js

Showing 1 changed file with 15 additions and 39 deletions
...@@ -2,11 +2,11 @@ const Address = require('./Address.js'); ...@@ -2,11 +2,11 @@ const Address = require('./Address.js');
2 const express = require('express'); 2 const express = require('express');
3 const request = require('request'); 3 const request = require('request');
4 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 4 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
5 -const TOKEN = '채널 토큰으로 변경' 5 +const TOKEN = 'YK56BfHFgpILrxRk1FZrdcouFguf5CBA5qxM3zfDH6N9jR/cfPxVdK1P9vZHAk69mZDSlSkXNLy25pzqJbXrn3y76hwmH0Kiuvx3OadFYcuidWSp7VYAj4SqJSljv/q5KoYAOE2il8jmQkf4bQKvXQdB04t89/1O/w1cDnyilFU='
6 const fs = require('fs'); 6 const fs = require('fs');
7 const path = require('path'); 7 const path = require('path');
8 const HTTPS = require('https'); 8 const HTTPS = require('https');
9 -const domain = "도메인 변경" 9 +const domain = "ec2-18-215-162-16.compute-1.amazonaws.com"
10 const sslport = 23023; 10 const sslport = 23023;
11 const bodyParser = require('body-parser'); 11 const bodyParser = require('body-parser');
12 const app = express(); 12 const app = express();
...@@ -14,13 +14,7 @@ const app = express(); ...@@ -14,13 +14,7 @@ const app = express();
14 14
15 console.log(Address.getAddress('석수동길')); 15 console.log(Address.getAddress('석수동길'));
16 16
17 -app.use(express.urlencoded({ extended: false })); 17 +app.use(bodyParser.json());
18 -app.use(express.json());
19 -
20 -app.get('',(req,res)=> {
21 - res.send('tset')
22 -})
23 -
24 app.post('/hook', function (req, res) { 18 app.post('/hook', function (req, res) {
25 var eventObj = req.body.events[0]; 19 var eventObj = req.body.events[0];
26 var source = eventObj.source; 20 var source = eventObj.source;
...@@ -55,35 +49,17 @@ app.post('/hook', function (req, res) { ...@@ -55,35 +49,17 @@ app.post('/hook', function (req, res) {
55 49
56 res.sendStatus(200); 50 res.sendStatus(200);
57 }); 51 });
52 +try {
53 + const option = {
54 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
55 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
56 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
57 + };
58 58
59 - 59 + HTTPS.createServer(option, app).listen(sslport, () => {
60 -app.get('/keyboard', (req, res) => { 60 + console.log(`[HTTPS] Server is started on port ${sslport}`);
61 - const data = {'type': 'text'} 61 + });
62 - res.json(data); 62 + } catch (error) {
63 -}); 63 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
64 - 64 + console.log(error);
65 -app.post('/message', (req, res) => {
66 - const question = req.body.userRequest.utterance;
67 - const goMain = '처음으로';
68 -
69 - if (question === '테스트') {
70 - const data = {
71 - 'version': '2.0',
72 - 'template': {
73 - 'outputs': [{
74 - 'simpleText': {
75 - 'text': '테스트'
76 - }
77 - }],
78 - 'quickReplies': [{
79 - 'label': goMain,
80 - 'action': 'message',
81 - 'messageText': goMain
82 - }]
83 - }
84 - }
85 } 65 }
...\ No newline at end of file ...\ No newline at end of file
86 - res.json(data);
87 -});
88 -
89 -app.listen(3000, () => console.log('node on 3000'));
...\ No newline at end of file ...\ No newline at end of file
......