오명준

Correct server executing file

Showing 1 changed file with 31 additions and 0 deletions
1 +const express = require('express');
2 +const fs = require('fs');
3 +const path = require('path');
4 +const HTTPS = require('https');
5 +
6 +const app = express();
7 +const domain = "www.probability.simulator.mooo.com"
8 +const sslport = 23023;
9 +
10 +app.get('/', function (req, res) {
11 + fs.readFile("list.html", function (error, data){
12 + res.writeHead(200, {"Content-Type" : "text/html"});
13 + res.end(data);
14 + });
15 +});
16 +
17 +try {
18 + const option = {
19 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
20 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
21 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
22 + };
23 +
24 + HTTPS.createServer(option, app).listen(sslport, () => {
25 + console.log(`[HTTPS] Server is started on port ${sslport}`);
26 + });
27 +} catch (error) {
28 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
29 + console.log(error);
30 +}
31 +
......