Ubuntu

Update server

Showing 1 changed file with 47 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 +
8 +const domain = "2020105636.oss-2021.tk"
9 +const sslport = 23023;
10 +
11 +app.use(express.static(__dirname));
12 +
13 +app.get('/', function(req, res){
14 + res.sendFile(__dirname + '/main.html');
15 +});
16 +
17 +app.get('/main.html', function(req, res){
18 + res.sendFile(__dirname + '/main.html');
19 +});
20 +
21 +app.get('/introduction.html', function(req, res){
22 + res.sendFile(__dirname + '/introduction.html');
23 +});
24 +
25 +app.get('/calendar.html', function(req, res){
26 + res.sendFile(__dirname + '/calendar.html');
27 +});
28 +
29 +
30 +app.get('/simulation.html', function(req, res){
31 + res.sendFile(__dirname + '/simulation.html');
32 +});
33 +
34 +try {
35 + const option = {
36 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
37 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
38 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
39 + };
40 +
41 + HTTPS.createServer(option, app).listen(sslport, () => {
42 + console.log(`[HTTPS] Server is started on port ${sslport}`);
43 + });
44 +} catch (error) {
45 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
46 + console.log(error);
47 +}
...\ No newline at end of file ...\ No newline at end of file