Seongwook Jin

ssl support

1 var express = require('express'); 1 var express = require('express');
2 const request = require('request'); 2 const request = require('request');
3 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 3 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
4 -const TOKEN = '채널 토큰으로 교체 해야 함' 4 +const TOKEN = '채널 토큰으로 변경'
5 +const fs = require('fs');
6 +const path = require('path');
7 +const HTTPS = require('https');
8 +const domain = "도메인 변경"
9 +const sslport = 23023;
5 10
6 const bodyParser = require('body-parser'); 11 const bodyParser = require('body-parser');
7 var app = express(); 12 var app = express();
...@@ -45,8 +50,18 @@ app.post('/hook', function (req, res) { ...@@ -45,8 +50,18 @@ app.post('/hook', function (req, res) {
45 res.sendStatus(200); 50 res.sendStatus(200);
46 }); 51 });
47 52
48 -var server = app.listen(23023, function () { 53 +try {
49 - var host = server.address().address 54 + const option = {
50 - var port = server.address().port 55 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
51 - console.log("Example app listening at http://%s:%s", host, port) 56 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
52 -}) 57 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
58 + };
59 +
60 + HTTPS.createServer(option, app).listen(sslport, () => {
61 + console.log(`[HTTPS] Server is started on port ${sslport}`);
62 + });
63 + } catch (error) {
64 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
65 + console.log(error);
66 + }
67 +
......
1 var express = require('express'); 1 var express = require('express');
2 const request = require('request'); 2 const request = require('request');
3 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 3 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
4 -const TOKEN = '채널 토큰으로 교체' 4 +const TOKEN = '채널 토큰'
5 const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' 5 const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
6 -const PAPAGO_ID = '네이버 클라이언트 ID' 6 +const PAPAGO_ID = '파파고 ID'
7 -const PAPAGO_SECRET = '네이버 클라이언트 Secret' 7 +const PAPAGO_SECRET = '파파고 Client Secret'
8 - 8 +const fs = require('fs');
9 +const path = require('path');
10 +const HTTPS = require('https');
11 +const domain = "도메인 명"
12 +const sslport = 23023;
9 const bodyParser = require('body-parser'); 13 const bodyParser = require('body-parser');
10 var app = express(); 14 var app = express();
11 app.use(bodyParser.json()); 15 app.use(bodyParser.json());
...@@ -66,8 +70,18 @@ function trans(replyToken, message) { ...@@ -66,8 +70,18 @@ function trans(replyToken, message) {
66 70
67 } 71 }
68 72
69 -var server = app.listen(23023, function () { 73 +try {
70 - var host = server.address().address 74 + const option = {
71 - var port = server.address().port 75 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
72 - console.log("Example app listening at http://%s:%s", host, port) 76 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
73 -}) 77 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
78 + };
79 +
80 + HTTPS.createServer(option, app).listen(sslport, () => {
81 + console.log(`[HTTPS] Server is started on port ${sslport}`);
82 + });
83 + } catch (error) {
84 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
85 + console.log(error);
86 + }
87 +
...\ No newline at end of file ...\ No newline at end of file
......
1 var express = require('express'); 1 var express = require('express');
2 const bodyParser = require('body-parser'); 2 const bodyParser = require('body-parser');
3 var app = express(); 3 var app = express();
4 +const fs = require('fs');
5 +const path = require('path');
6 +const HTTPS = require('https');
7 +const domain = "도메인 변경 처리"
8 +const sslport = 23023;
9 +
4 app.use(bodyParser.json()); 10 app.use(bodyParser.json());
5 11
6 app.post('/hook', function (request, response) { 12 app.post('/hook', function (request, response) {
...@@ -18,8 +24,19 @@ app.post('/hook', function (request, response) { ...@@ -18,8 +24,19 @@ app.post('/hook', function (request, response) {
18 response.sendStatus(200); 24 response.sendStatus(200);
19 }); 25 });
20 26
21 -var server = app.listen(23023, function () { 27 +
22 - var host = server.address().address 28 +try {
23 - var port = server.address().port 29 + const option = {
24 - console.log("Example app listening at http://%s:%s", host, port) 30 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
25 -}) 31 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
32 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
33 + };
34 +
35 + HTTPS.createServer(option, app).listen(sslport, () => {
36 + console.log(`[HTTPS] Server is started on port ${sslport}`);
37 + });
38 + } catch (error) {
39 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
40 + console.log(error);
41 + }
42 +
......