백엔드 config 파일들 생성
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -190,7 +190,6 @@ docker-compose.prod.yml
|
||||
.env.docker
|
||||
|
||||
# 설정 파일들
|
||||
config/
|
||||
configs/
|
||||
settings/
|
||||
*.config.js
|
||||
|
||||
45
backend-node/src/config/database.ts
Normal file
45
backend-node/src/config/database.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import config from "./environment";
|
||||
|
||||
// Prisma 클라이언트 인스턴스 생성
|
||||
const prisma = new PrismaClient({
|
||||
datasources: {
|
||||
db: {
|
||||
url: config.databaseUrl,
|
||||
},
|
||||
},
|
||||
log: config.debug ? ["query", "info", "warn", "error"] : ["error"],
|
||||
});
|
||||
|
||||
// 데이터베이스 연결 테스트
|
||||
async function testConnection() {
|
||||
try {
|
||||
await prisma.$connect();
|
||||
console.log("✅ 데이터베이스 연결 성공");
|
||||
} catch (error) {
|
||||
console.error("❌ 데이터베이스 연결 실패:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 애플리케이션 종료 시 연결 해제
|
||||
process.on("beforeExit", async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
|
||||
process.on("SIGINT", async () => {
|
||||
await prisma.$disconnect();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on("SIGTERM", async () => {
|
||||
await prisma.$disconnect();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// 초기 연결 테스트 (개발 환경에서만)
|
||||
if (config.nodeEnv === "development") {
|
||||
testConnection();
|
||||
}
|
||||
|
||||
export default prisma;
|
||||
117
backend-node/src/config/environment.ts
Normal file
117
backend-node/src/config/environment.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import dotenv from "dotenv";
|
||||
import path from "path";
|
||||
|
||||
// .env 파일 로드
|
||||
dotenv.config({ path: path.resolve(process.cwd(), ".env") });
|
||||
|
||||
interface Config {
|
||||
// 서버 설정
|
||||
port: number;
|
||||
host: string;
|
||||
nodeEnv: string;
|
||||
|
||||
// 데이터베이스 설정
|
||||
databaseUrl: string;
|
||||
|
||||
// JWT 설정
|
||||
jwt: {
|
||||
secret: string;
|
||||
expiresIn: string;
|
||||
refreshExpiresIn: string;
|
||||
};
|
||||
|
||||
// 보안 설정
|
||||
bcryptRounds: number;
|
||||
sessionSecret: string;
|
||||
|
||||
// CORS 설정
|
||||
cors: {
|
||||
origin: string;
|
||||
credentials: boolean;
|
||||
};
|
||||
|
||||
// 로깅 설정
|
||||
logging: {
|
||||
level: string;
|
||||
file: string;
|
||||
};
|
||||
|
||||
// API 설정
|
||||
apiPrefix: string;
|
||||
apiVersion: string;
|
||||
|
||||
// 파일 업로드 설정
|
||||
maxFileSize: number;
|
||||
uploadDir: string;
|
||||
|
||||
// 이메일 설정
|
||||
smtpHost: string;
|
||||
smtpPort: number;
|
||||
smtpUser: string;
|
||||
smtpPass: string;
|
||||
|
||||
// Redis 설정
|
||||
redisUrl: string;
|
||||
|
||||
// 개발 환경 설정
|
||||
debug: boolean;
|
||||
showErrorDetails: boolean;
|
||||
}
|
||||
|
||||
const config: Config = {
|
||||
// 서버 설정
|
||||
port: parseInt(process.env.PORT || "3000", 10),
|
||||
host: process.env.HOST || "0.0.0.0",
|
||||
nodeEnv: process.env.NODE_ENV || "development",
|
||||
|
||||
// 데이터베이스 설정
|
||||
databaseUrl:
|
||||
process.env.DATABASE_URL ||
|
||||
"postgresql://postgres:postgres@localhost:5432/ilshin",
|
||||
|
||||
// JWT 설정
|
||||
jwt: {
|
||||
secret: process.env.JWT_SECRET || "ilshin-plm-super-secret-jwt-key-2024",
|
||||
expiresIn: process.env.JWT_EXPIRES_IN || "24h",
|
||||
refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES_IN || "7d",
|
||||
},
|
||||
|
||||
// 보안 설정
|
||||
bcryptRounds: parseInt(process.env.BCRYPT_ROUNDS || "12", 10),
|
||||
sessionSecret: process.env.SESSION_SECRET || "ilshin-plm-session-secret-2024",
|
||||
|
||||
// CORS 설정
|
||||
cors: {
|
||||
origin: process.env.CORS_ORIGIN || "http://localhost:9771",
|
||||
credentials: process.env.CORS_CREDENTIALS === "true",
|
||||
},
|
||||
|
||||
// 로깅 설정
|
||||
logging: {
|
||||
level: process.env.LOG_LEVEL || "info",
|
||||
file: process.env.LOG_FILE || "logs/app.log",
|
||||
},
|
||||
|
||||
// API 설정
|
||||
apiPrefix: process.env.API_PREFIX || "/api",
|
||||
apiVersion: process.env.API_VERSION || "v1",
|
||||
|
||||
// 파일 업로드 설정
|
||||
maxFileSize: parseInt(process.env.MAX_FILE_SIZE || "10485760", 10),
|
||||
uploadDir: process.env.UPLOAD_DIR || "uploads",
|
||||
|
||||
// 이메일 설정
|
||||
smtpHost: process.env.SMTP_HOST || "smtp.gmail.com",
|
||||
smtpPort: parseInt(process.env.SMTP_PORT || "587", 10),
|
||||
smtpUser: process.env.SMTP_USER || "",
|
||||
smtpPass: process.env.SMTP_PASS || "",
|
||||
|
||||
// Redis 설정
|
||||
redisUrl: process.env.REDIS_URL || "redis://localhost:6379",
|
||||
|
||||
// 개발 환경 설정
|
||||
debug: process.env.DEBUG === "true",
|
||||
showErrorDetails: process.env.SHOW_ERROR_DETAILS === "true",
|
||||
};
|
||||
|
||||
export default config;
|
||||
Reference in New Issue
Block a user