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