해당 서비스 도커화 성공, 룰 추가, 로그인 오류 수정, 소문자 룰 어느정도 해결

This commit is contained in:
Hyungi Ahn
2025-08-01 15:55:27 +09:00
parent ef06cec8d6
commit 809b2af53e
6418 changed files with 1922672 additions and 69 deletions

View File

@@ -6,15 +6,7 @@ const helmet = require('helmet');
const rateLimit = require('express-rate-limit');
const app = express();
// ✅ Health check (맨 처음에 등록 - 모든 미들웨어보다 우선)
app.get('/api/health', (req, res) => {
console.log('🟢 Health check 호출됨!');
res.status(200).json({
status: 'healthy',
service: 'Hyungi API',
timestamp: new Date().toISOString()
});
});
// 헬스체크와 개발용 엔드포인트는 CORS 이후에 등록
// ✅ 보안 헤더 설정 (Helmet)
app.use(helmet({
@@ -39,12 +31,77 @@ app.use(helmet({
app.use(express.urlencoded({ extended: true, limit: '50mb' }));
app.use(express.json({ limit: '50mb' }));
//개발용
//개발용 CORS 설정 (수정됨)
app.use(cors({
origin: true, // 모든 origin 허용 (개발용)
credentials: true
origin: function (origin, callback) {
// 개발 환경에서는 모든 origin 허용
console.log('🌐 CORS Origin 요청:', origin);
const allowedOrigins = [
'http://localhost:20000', // 웹 UI
'http://localhost:3005', // API 서버
'http://localhost:3000', // 개발 포트
'http://127.0.0.1:20000', // 로컬호스트 대체
];
// origin이 없는 경우 (직접 접근) 허용
if (!origin) {
console.log('✅ Origin 없음 - 허용');
return callback(null, true);
}
// 허용된 origin인지 확인
if (allowedOrigins.includes(origin)) {
console.log('✅ 허용된 Origin:', origin);
return callback(null, true);
}
// 개발 환경에서는 모든 localhost 허용
if (origin.includes('localhost') || origin.includes('127.0.0.1')) {
console.log('✅ 로컬호스트 허용:', origin);
return callback(null, true);
}
console.log('❌ 차단된 Origin:', origin);
callback(null, false);
},
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With']
}));
// ✅ Health check (CORS 이후에 등록)
app.get('/api/health', (req, res) => {
console.log('🟢 Health check 호출됨!');
res.status(200).json({
status: 'healthy',
service: 'Hyungi API',
timestamp: new Date().toISOString()
});
});
// ✅ 개발용 Ping 엔드포인트
app.get('/api/ping', (req, res) => {
console.log('🏓 Ping 요청 받음!');
res.status(200).json({
message: 'pong',
timestamp: new Date().toISOString()
});
});
// ✅ 서버 상태 엔드포인트
app.get('/api/status', (req, res) => {
console.log('📊 Status 요청 받음!');
res.status(200).json({
status: 'running',
service: 'Hyungi API',
version: '2.1.0',
environment: process.env.NODE_ENV || 'development',
uptime: process.uptime(),
timestamp: new Date().toISOString()
});
});
// ✅ CORS 설정: 허용 origin 명시 (수정된 버전)
//app.use(cors({
// origin: function (origin, callback) {
@@ -106,11 +163,11 @@ const apiLimiter = rateLimit({
legacyHeaders: false,
});
// 로그인 API 속도 제한 (더 엄격하게)
// 로그인 API 속도 제한 (개발 환경에서 완화됨)
const loginLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15분
max: process.env.LOGIN_RATE_LIMIT_MAX_REQUESTS || 5,
message: '너무 많은 로그인 시도입니다. 15분 후에 다시 시도하세요.',
windowMs: 5 * 60 * 1000, // 5분으로 단축
max: process.env.LOGIN_RATE_LIMIT_MAX_REQUESTS || 20, // 5 -> 20으로 증가
message: '너무 많은 로그인 시도입니다. 5분 후에 다시 시도하세요.',
standardHeaders: true,
legacyHeaders: false,
skipSuccessfulRequests: true, // 성공한 요청은 카운트하지 않음
@@ -210,7 +267,9 @@ app.use('/api/*', (req, res, next) => {
'/api/auth/login',
'/api/auth/refresh-token',
'/api/auth/check-password-strength',
'/api/health'
'/api/health',
'/api/ping', // 개발용 핑
'/api/status' // 서버 상태
];
// 정확한 경로 매칭 확인