From 8da6ace043de6589259ab1f09b1627dd46eba4c6 Mon Sep 17 00:00:00 2001 From: jungeun Date: Sat, 7 Sep 2024 18:14:01 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20https=20=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- src/index.js | 38 ++++++++--- src/test.html | 180 +++++++++++++++++++++++++------------------------- 3 files changed, 121 insertions(+), 100 deletions(-) diff --git a/.gitignore b/.gitignore index 25c8fdb..93cbb61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -package-lock.json \ No newline at end of file +package-lock.json +config \ No newline at end of file diff --git a/src/index.js b/src/index.js index b8ffc39..5e99f4d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,15 +1,35 @@ +const fs = require('fs'); +const https = require('https'); const express = require('express'); -const http = require('http'); const cors = require('cors'); -const mediasoup = require('mediasoup'); const SockJS = require('sockjs'); +const mediasoup = require('mediasoup'); +const path = require('path'); + +// 파일 경로를 절대 경로로 설정 +const privateKey = fs.readFileSync(path.join(__dirname, 'config', '_wildcard.exampel.dev+3-key.pem')); +const certificate = fs.readFileSync(path.join(__dirname, 'config', '_wildcard.exampel.dev+3.pem')); +const credentials = { key: privateKey, cert: certificate }; + +// Express 애플리케이션 생성 const app = express(); -const server = http.createServer(app); -const sockjsServer = SockJS.createServer(); -sockjsServer.installHandlers(server, { prefix: '/sockjs' }); -app.use(cors()); +// CORS 설정 +const corsOptions = { + origin: '*', // 모든 도메인 허용 + methods: ['GET', 'POST'], + allowedHeaders: ['Content-Type', 'Authorization'] +}; + +app.use(cors(corsOptions)); + +// HTTPS 서버 생성 +const httpsServer = https.createServer(credentials, app); + +// SockJS 서버 생성 +const sockjsServer = SockJS.createServer(); +sockjsServer.installHandlers(httpsServer, { prefix: '/sockjs' }); const workers = []; const mediaCodecs = [ @@ -119,6 +139,6 @@ app.get('/', (req, res) => { res.sendFile(__dirname + '/test.html'); }); -server.listen(9000, () => { - console.log("⭐️ 서버가 localhost:9000에서 실행 중입니다! "); -}); +httpsServer.listen(9000, () => { + console.log('🚀 HTTPS 서버가 https://localhost:9000에서 실행 중입니다!'); + }); diff --git a/src/test.html b/src/test.html index 0e01302..dfb51a8 100644 --- a/src/test.html +++ b/src/test.html @@ -3,7 +3,7 @@ - 화면 공유 + 화면 공유 (로컬 테스트) -

화면 공유

+

화면 공유 (로컬 테스트)

- - -
+ +
- + + - + \ No newline at end of file