강동현

개발 환경에 맞게 서버 설정 조정

......@@ -18,4 +18,6 @@ RUN yarn build
EXPOSE 3000
ENV NODE_ENV production
CMD [ "node", "dist/server/index.js" ]
......
import express from "express";
import socketIo, { Server as IoServer } from "socket.io";
import { createServer } from "https";
import { createServer as createServerHttps } from "https";
import { createServer as createServerHttp } from "http";
import { RoomManager } from "./room/RoomManager";
import { Connection } from "./connection/Connection";
import { SocketIoWrapper } from "./connection/SocketWrapper";
......@@ -13,21 +14,28 @@ export class Server {
constructor(port: number) {
this.port = port;
console.log(`Running in ${process.env.NODE_ENV} mode.`);
const app = express();
const server = createServer(
{
cert: readFileSync(
"/etc/letsencrypt/live/2020105578.oss2021.tk/cert.pem"
),
key: readFileSync(
"/etc/letsencrypt/live/2020105578.oss2021.tk/privkey.pem"
),
ca: readFileSync(
"/etc/letsencrypt/live/2020105578.oss2021.tk/fullchain.pem"
),
},
app
);
let server;
if (process.env.NODE_ENV === "development") {
server = createServerHttp(app);
} else {
server = createServerHttps(
{
cert: readFileSync(
"/etc/letsencrypt/live/2020105578.oss2021.tk/cert.pem"
),
key: readFileSync(
"/etc/letsencrypt/live/2020105578.oss2021.tk/privkey.pem"
),
ca: readFileSync(
"/etc/letsencrypt/live/2020105578.oss2021.tk/fullchain.pem"
),
},
app
);
}
this.io = new socketIo.Server(server, {
cors: {
origin: "*",
......
import { Server } from "./Server";
process.env.NODE_ENV =
process.env.NODE_ENV &&
process.env.NODE_ENV.trim().toLowerCase() == "production"
? "production"
: "development";
new Server(3000);
......
import React from "react";
import { io } from "socket.io-client";
export const socket = io(`https://${window.location.hostname}:3000/`);
export const socket = io(
`${window.location.protocol}//${window.location.hostname}:3000/`
);
const SocketContext = React.createContext(socket);
export const SocketProvider = SocketContext.Provider;
......