강동현
Builds for 1 pipeline failed in 1 minute 12 seconds

Merge branch 'feature/environment' into develop

......@@ -13,20 +13,7 @@ Test Server:
- yarn install
- yarn test
Build Server:
Build:
stage: build
script:
- cd common
- yarn install
- cd ../server
- yarn install
- yarn build
Build Web:
stage: build
script:
- cd common
- yarn install
- cd ../web
- npm install
- npm build
- HOST=2020105578.oss2021.tk SSL_CERT=/etc/letsencrypt/live/2020105578.oss2021.tk/cert.pem SSL_KEY=/etc/letsencrypt/live/2020105578.oss2021.tk/privkey.pem SSL_CA=/etc/letsencrypt/live/2020105578.oss2021.tk/fullchain.pem docker-compose build --no-cache
......
......@@ -10,11 +10,20 @@ services:
- "3000:3000"
volumes:
- /etc/letsencrypt:/etc/letsencrypt
environment:
- SSL_CERT=${SSL_CERT}
- SSL_KEY=${SSL_KEY}
- SSL_CA=${SSL_CA}
web:
build:
context: .
dockerfile: ./web/Dockerfile
args:
- HOST=${HOST}
- SSL_CERT=${SSL_CERT}
- SSL_KEY=${SSL_KEY}
- SSL_CA=${SSL_CA}
restart: unless-stopped
ports:
- "443:443"
......
......@@ -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,22 @@ export class Server {
constructor(port: number) {
this.port = port;
console.log(`Running in ${process.env.NODE_ENV} mode.`);
const app = express();
const server = createServer(
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"
),
cert: readFileSync(process.env.SSL_CERT as string),
key: readFileSync(process.env.SSL_KEY as string),
ca: readFileSync(process.env.SSL_CA as string),
},
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);
......
......@@ -16,7 +16,18 @@ RUN yarn build
FROM nginx:latest
COPY web/default.conf /etc/nginx/conf.d/default.conf
ARG HOST
ENV HOST ${HOST}
ARG SSL_CERT
ENV SSL_CERT ${SSL_CERT}
ARG SSL_KEY
ENV SSL_KEY ${SSL_KEY}}
ARG SSL_CA
ENV SSL_CA ${SSL_CA}}
COPY web/default.conf /etc/nginx/conf.d/default_temp
RUN envsubst < /etc/nginx/conf.d/default_temp > /etc/nginx/conf.d/default.conf
COPY --from=build /usr/web/build /usr/web/build
EXPOSE 443
......
......@@ -5,10 +5,10 @@ server {
server {
listen 443 ssl default_server;
server_name 2020105578.oss2021.tk;
server_name $HOST;
ssl_certificate /etc/letsencrypt/live/2020105578.oss2021.tk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/2020105578.oss2021.tk/privkey.pem;
ssl_certificate $SSL_CA;
ssl_certificate_key $SSL_KEY;
location / {
root /usr/web/build;
......
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;
......