Skip to content

Commit

Permalink
[fix] HTTPS 적용 후 채팅 안되는 문제 해결 (#124)
Browse files Browse the repository at this point in the history
* fix: 채팅 연결 버그 수정

* fix: Production 환경에서만 인증서를 가져오도록 수정

* fix: dotenv 코드 제거
  • Loading branch information
kkg5 authored Dec 5, 2023
1 parent a4e9d11 commit 51b3b8d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion client/src/pages/BroadcastPage/BroadcastPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const BroadcastPage = () => {
}

useEffect(() => {
socket.current = io('http://localhost:3000', { withCredentials: true })
socket.current = io('https://api.gbs-live.site', { withCredentials: true })

socket.current.emit('join', { room: id })

Expand Down
2 changes: 1 addition & 1 deletion server/api-server/src/auth/strategy/naver.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Strategy } from 'passport-naver-v2';
import { PassportStrategy } from '@nestjs/passport';
import { HttpException, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { AuthService } from '../auth.service';

@Injectable()
Expand Down
3 changes: 0 additions & 3 deletions server/api-server/src/chat/chat.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { Server, Socket } from 'socket.io';
import { JoinPayload } from './dto/join-payload.dto';
import { ChatPayload } from './dto/chat-payload';
import { Logger } from '@nestjs/common';

import * as dotenv from 'dotenv';
import { UsersService } from 'src/users/users.service';
dotenv.config();

@WebSocketGateway({
cors: {
Expand Down
28 changes: 14 additions & 14 deletions server/api-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import { getSession } from './common/redis.session';
import { RedisIoAdapter } from './common/redis.adapter';
import * as passport from 'passport';
import * as fs from 'fs';
import * as http from 'http';
import * as https from 'https';
import * as express from 'express';
import { ExpressAdapter } from '@nestjs/platform-express';
import * as process from 'process';
import { INestApplication } from '@nestjs/common';

async function bootstrap() {
const httpsOptions = {
key: fs.readFileSync(process.env.KEY_PATH),
cert: fs.readFileSync(process.env.CERT_PATH),
};
const server = express();
const app = await NestFactory.create(AppModule, new ExpressAdapter(server));
let app: INestApplication<any>;

if (process.env.NODE_ENV === 'production') {
app = await NestFactory.create(AppModule, {
httpsOptions: {
key: fs.readFileSync(process.env.KEY_PATH),
cert: fs.readFileSync(process.env.CERT_PATH),
},
});
} else {
app = await NestFactory.create(AppModule);
}

const session = getSession();
app.use(session);
Expand All @@ -27,10 +30,7 @@ async function bootstrap() {
await redisIoAdapter.connectToRedis();
app.useWebSocketAdapter(redisIoAdapter);

await app.init();

const httpServer = http.createServer(server).listen(3000);
const httpsServer = https.createServer(httpsOptions, server).listen(443);
await app.listen(process.env.PORT);
}

bootstrap();

0 comments on commit 51b3b8d

Please sign in to comment.