서연진

Connect aws

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