Skip to content

Commit

Permalink
fix: https 모드
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Aug 16, 2023
1 parent 9cac151 commit 6f1957b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
13 changes: 10 additions & 3 deletions backend/src/@types/process.env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ export declare global {
/** 42 API OAuth 리다이렉트 URL */
REDIRECT_URL: string;

/** 레포지토리 선택 모드 */
MODE: 'local' | 'RDS' | 'prod';
/**
* 레포지토리 선택 모드
*
* - local: 호스트 머신의 DB에 연결
* - prod: 도커 컨테이너의 DB에 연결
* - RDS: AWS RDS에 연결
* - https: RDS + SSL에 연결
*/
MODE: 'local' | 'RDS' | 'prod' | 'https';

// local 또는 prod MODE에서
/** MySQL 데이터베이스 이름 */
Expand All @@ -48,7 +55,7 @@ export declare global {
/** MySQL 데이터베이스 사용자 이름 */
MYSQL_USER?: string;

// RDS MODE에서
// RDS 또는 https MODE에서
/** RDS 데이터베이스 이름 */
RDS_DB_NAME?: string;
/** RDS 데이터베이스 주소 */
Expand Down
10 changes: 7 additions & 3 deletions backend/src/config/JwtOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import { z } from 'zod';
import { JwtOption, OauthUrlOption } from './config.type';
import { nonempty } from './envObject';
import { Mode } from './modeOption';
import { match } from 'ts-pattern';

type getJwtOption = (mode: Mode) => (option: OauthUrlOption) => JwtOption;
export const getJwtOption: getJwtOption = (mode) => ({ redirectURL, clientURL }) => {
const redirectDomain = new URL(redirectURL).hostname;
const clientDomain = new URL(clientURL).hostname;
const secure = mode === 'prod' || mode === 'https';

const issuer = mode === 'local' ? 'localhost' : redirectDomain;
const domain = mode === 'prod' ? clientDomain : 'localhost';
const secure = mode === 'prod';
const issuer = secure ? redirectDomain : 'localhost';
const domain = match(mode)
.with('prod', () => clientDomain)
.with('https', () => undefined)
.otherwise(() => 'localhost');

return { issuer, domain, secure };
};
Expand Down
2 changes: 1 addition & 1 deletion backend/src/config/config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type JwtOption = {
issuer: string | 'localhost'

/** JWT 도메인 */
domain: string | 'localhost'
domain: string | undefined

/** Cookie Secure 사용 여부 */
secure: boolean;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/config/getConnectOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Mode } from './modeOption';
/** DB 모드에 따라 사용할 DB 연결 옵션 스키마를 고르는 함수 */
const getConnectOptionSchema = (mode: Mode) => {
if (mode === 'local') return localSchema;
if (mode === 'RDS') return rdsSchema;
if (mode === 'RDS' || mode === 'https') return rdsSchema;
return prodSchema;
};

Expand Down
2 changes: 1 addition & 1 deletion backend/src/config/modeOption.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from 'zod';

/** DB 모드를 정의하는 스키마 */
export const modeSchema = z.enum(['local', 'RDS', 'prod']);
export const modeSchema = z.enum(['local', 'RDS', 'prod', 'https']);

/** DB 선택 모드 */
export type Mode = z.infer<typeof modeSchema>;
Expand Down
6 changes: 4 additions & 2 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ services:
restart: on-failure
entrypoint: ["./node_modules/.bin/vite-node", "src/server.ts"]
volumes:
- ./backend/src:/app/backend/src

- ./logs/backend:/app/backend/logs
env_file: .env.rds
env_file: .env.https
environment:
- MODE=RDS
- MODE=https
- TZ=Asia/Seoul

0 comments on commit 6f1957b

Please sign in to comment.