김대욱

app.js v1.0

1 const request = require('request'); 1 const request = require('request');
2 +const fs = require('fs');
3 +const path = require('path');
4 +const HTTPS = require('https');
5 +const domain = "www.osstestdw.ml"
6 +const sslport = 23023;
2 var express = require('express') 7 var express = require('express')
3 var app = express() 8 var app = express()
4 9
...@@ -157,4 +162,17 @@ var server = app.listen(23023, function(){ ...@@ -157,4 +162,17 @@ var server = app.listen(23023, function(){
157 console.log('App listening at http://%s:%s', host, port) 162 console.log('App listening at http://%s:%s', host, port)
158 }) 163 })
159 164
160 - 165 +try {
166 + const option = {
167 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
168 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
169 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
170 + };
171 +
172 + HTTPS.createServer(option, app).listen(sslport, () => {
173 + console.log(`[HTTPS] Server is started on port ${sslport}`);
174 + });
175 +} catch (error) {
176 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
177 + console.log(error);
178 +}
......