강동현

express에 https적용

...@@ -8,6 +8,8 @@ services: ...@@ -8,6 +8,8 @@ services:
8 restart: unless-stopped 8 restart: unless-stopped
9 ports: 9 ports:
10 - "3000:3000" 10 - "3000:3000"
11 + volumes:
12 + - /etc/letsencrypt:/etc/letsencrypt
11 13
12 web: 14 web:
13 build: 15 build:
......
1 import express from "express"; 1 import express from "express";
2 import socketIo, { Server as IoServer } from "socket.io"; 2 import socketIo, { Server as IoServer } from "socket.io";
3 -import { createServer } from "http"; 3 +import { createServer } from "https";
4 import { RoomManager } from "./room/RoomManager"; 4 import { RoomManager } from "./room/RoomManager";
5 import { Connection } from "./connection/Connection"; 5 import { Connection } from "./connection/Connection";
6 import { SocketIoWrapper } from "./connection/SocketWrapper"; 6 import { SocketIoWrapper } from "./connection/SocketWrapper";
7 +import { readFileSync } from "fs";
7 8
8 export class Server { 9 export class Server {
9 public readonly port: number; 10 public readonly port: number;
...@@ -13,7 +14,20 @@ export class Server { ...@@ -13,7 +14,20 @@ export class Server {
13 this.port = port; 14 this.port = port;
14 15
15 const app = express(); 16 const app = express();
16 - const server = createServer(app); 17 + const server = createServer(
18 + {
19 + cert: readFileSync(
20 + "/etc/letsencrypt/live/2020105578.oss2021.tk/cert.pem"
21 + ),
22 + key: readFileSync(
23 + "/etc/letsencrypt/live/2020105578.oss2021.tk/privkey.pem"
24 + ),
25 + ca: readFileSync(
26 + "/etc/letsencrypt/live/2020105578.oss2021.tk/fullchain.pem"
27 + ),
28 + },
29 + app
30 + );
17 this.io = new socketIo.Server(server, { 31 this.io = new socketIo.Server(server, {
18 cors: { 32 cors: {
19 origin: "*", 33 origin: "*",
......