feat: 다수 기능 개선 - 순찰, 출근, 작업분석, 모바일 UI 등
- 순찰/점검 기능 개선 (zone-detail 페이지 추가) - 출근/근태 시스템 개선 (연차 조회, 근무현황) - 작업분석 대분류 그룹화 및 마이그레이션 스크립트 - 모바일 네비게이션 UI 추가 - NAS 배포 도구 및 문서 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
89
deploy/tkfb-package/api.hyungi.net/config/cors.js
Normal file
89
deploy/tkfb-package/api.hyungi.net/config/cors.js
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* CORS 설정
|
||||
*
|
||||
* Cross-Origin Resource Sharing 설정
|
||||
*
|
||||
* @author TK-FB-Project
|
||||
* @since 2025-12-11
|
||||
*/
|
||||
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
/**
|
||||
* 허용된 Origin 목록
|
||||
*/
|
||||
const allowedOrigins = [
|
||||
'http://localhost:20000', // 웹 UI
|
||||
'http://localhost:3005', // API 서버
|
||||
'http://localhost:3000', // 개발 포트
|
||||
'http://127.0.0.1:20000', // 로컬호스트 대체
|
||||
'http://127.0.0.1:3005',
|
||||
'http://127.0.0.1:3000'
|
||||
];
|
||||
|
||||
/**
|
||||
* CORS 설정 옵션
|
||||
*/
|
||||
const corsOptions = {
|
||||
/**
|
||||
* Origin 검증 함수
|
||||
*/
|
||||
origin: function (origin, callback) {
|
||||
// Origin이 없는 경우 (직접 접근, Postman 등)
|
||||
if (!origin) {
|
||||
logger.debug('CORS: Origin 없음 - 허용');
|
||||
return callback(null, true);
|
||||
}
|
||||
|
||||
// 허용된 Origin 확인
|
||||
if (allowedOrigins.includes(origin)) {
|
||||
logger.debug('CORS: 허용된 Origin', { origin });
|
||||
return callback(null, true);
|
||||
}
|
||||
|
||||
// 개발 환경에서는 모든 localhost 허용
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
if (origin.includes('localhost') || origin.includes('127.0.0.1')) {
|
||||
logger.debug('CORS: 로컬호스트 허용 (개발 모드)', { origin });
|
||||
return callback(null, true);
|
||||
}
|
||||
}
|
||||
|
||||
// 로컬 네트워크 IP 자동 허용 (192.168.x.x)
|
||||
if (origin.match(/^http:\/\/192\.168\.\d+\.\d+(:\d+)?$/)) {
|
||||
logger.debug('CORS: 로컬 네트워크 IP 허용', { origin });
|
||||
return callback(null, true);
|
||||
}
|
||||
|
||||
// 차단
|
||||
logger.warn('CORS: 차단된 Origin', { origin });
|
||||
callback(new Error(`CORS 정책에 의해 차단됨: ${origin}`));
|
||||
},
|
||||
|
||||
/**
|
||||
* 인증 정보 포함 허용
|
||||
*/
|
||||
credentials: true,
|
||||
|
||||
/**
|
||||
* 허용된 HTTP 메소드
|
||||
*/
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
|
||||
|
||||
/**
|
||||
* 허용된 헤더
|
||||
*/
|
||||
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
|
||||
|
||||
/**
|
||||
* 노출할 헤더
|
||||
*/
|
||||
exposedHeaders: ['Content-Range', 'X-Content-Range'],
|
||||
|
||||
/**
|
||||
* Preflight 요청 캐시 시간 (초)
|
||||
*/
|
||||
maxAge: 86400 // 24시간
|
||||
};
|
||||
|
||||
module.exports = corsOptions;
|
||||
79
deploy/tkfb-package/api.hyungi.net/config/database.js
Normal file
79
deploy/tkfb-package/api.hyungi.net/config/database.js
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* 데이터베이스 연결 설정
|
||||
*
|
||||
* MySQL/MariaDB 커넥션 풀 관리
|
||||
* - 환경 변수 기반 설정
|
||||
* - 자동 재연결 (최대 5회 재시도)
|
||||
* - UTF-8MB4 문자셋 지원
|
||||
*
|
||||
* @author TK-FB-Project
|
||||
* @since 2025-12-11
|
||||
*/
|
||||
|
||||
require('dotenv').config();
|
||||
const mysql = require('mysql2/promise');
|
||||
const retry = require('async-retry');
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
let pool = null;
|
||||
|
||||
async function initPool() {
|
||||
if (pool) return pool;
|
||||
|
||||
const {
|
||||
DB_HOST, DB_PORT, DB_USER,
|
||||
DB_PASSWORD, DB_NAME,
|
||||
DB_SOCKET, DB_CONN_LIMIT = '10'
|
||||
} = process.env;
|
||||
|
||||
if (!DB_USER || !DB_PASSWORD || !DB_NAME) {
|
||||
throw new Error('필수 환경변수(DB_USER, DB_PASSWORD, DB_NAME)가 없습니다.');
|
||||
}
|
||||
if (!DB_SOCKET && !DB_HOST) {
|
||||
throw new Error('DB_SOCKET이 없으면 DB_HOST가 반드시 필요합니다.');
|
||||
}
|
||||
|
||||
await retry(async () => {
|
||||
const config = {
|
||||
user: DB_USER,
|
||||
password: DB_PASSWORD,
|
||||
database: DB_NAME,
|
||||
waitForConnections: true,
|
||||
connectionLimit: parseInt(DB_CONN_LIMIT, 10),
|
||||
queueLimit: 0,
|
||||
charset: 'utf8mb4'
|
||||
};
|
||||
if (DB_SOCKET) {
|
||||
config.socketPath = DB_SOCKET;
|
||||
} else {
|
||||
config.host = DB_HOST;
|
||||
config.port = parseInt(DB_PORT, 10);
|
||||
}
|
||||
|
||||
pool = mysql.createPool(config);
|
||||
|
||||
// 첫 연결 검증
|
||||
const conn = await pool.getConnection();
|
||||
await conn.query('SET NAMES utf8mb4');
|
||||
conn.release();
|
||||
|
||||
const connectionInfo = DB_SOCKET ? `socket=${DB_SOCKET}` : `${DB_HOST}:${DB_PORT}`;
|
||||
logger.info('MariaDB 연결 성공', {
|
||||
connection: connectionInfo,
|
||||
database: DB_NAME,
|
||||
connectionLimit: parseInt(DB_CONN_LIMIT, 10)
|
||||
});
|
||||
}, {
|
||||
retries: 5,
|
||||
factor: 2,
|
||||
minTimeout: 1000
|
||||
});
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
async function getDb() {
|
||||
return initPool();
|
||||
}
|
||||
|
||||
module.exports = { getDb };
|
||||
115
deploy/tkfb-package/api.hyungi.net/config/middleware.js
Normal file
115
deploy/tkfb-package/api.hyungi.net/config/middleware.js
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 미들웨어 설정
|
||||
*
|
||||
* Express 애플리케이션의 모든 미들웨어를 등록하는 중앙화된 설정 파일
|
||||
*
|
||||
* @author TK-FB-Project
|
||||
* @since 2025-12-11
|
||||
*/
|
||||
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const helmet = require('helmet');
|
||||
const compression = require('compression');
|
||||
const path = require('path');
|
||||
const helmetOptions = require('./security');
|
||||
const corsOptions = require('./cors');
|
||||
const { responseMiddleware } = require('../utils/responseFormatter');
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
/**
|
||||
* 모든 미들웨어를 Express 앱에 등록
|
||||
* @param {Express.Application} app - Express 애플리케이션 인스턴스
|
||||
*/
|
||||
function setupMiddlewares(app) {
|
||||
// 보안 헤더 설정 (Helmet)
|
||||
app.use(helmet(helmetOptions));
|
||||
|
||||
// 성능 최적화 - Compression
|
||||
app.use(compression({
|
||||
filter: (req, res) => {
|
||||
if (req.headers['x-no-compression']) {
|
||||
return false;
|
||||
}
|
||||
return compression.filter(req, res);
|
||||
},
|
||||
level: 6, // 압축 레벨 (1-9, 6이 기본값)
|
||||
threshold: 1024 // 1KB 이상만 압축
|
||||
}));
|
||||
|
||||
// 요청 바디 파싱 - 용량 제한 확장
|
||||
app.use(express.urlencoded({ extended: true, limit: '50mb' }));
|
||||
app.use(express.json({ limit: '50mb' }));
|
||||
|
||||
// 응답 포맷터 미들웨어
|
||||
app.use(responseMiddleware);
|
||||
|
||||
// CORS 설정
|
||||
app.use(cors(corsOptions));
|
||||
|
||||
// 정적 파일 서빙
|
||||
app.use(express.static(path.join(__dirname, '../public')));
|
||||
app.use('/uploads', express.static(path.join(__dirname, '../uploads')));
|
||||
|
||||
// Rate Limiting - API 요청 제한
|
||||
const rateLimit = require('express-rate-limit');
|
||||
|
||||
// 일반 API 요청 제한
|
||||
const apiLimiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000, // 15분
|
||||
max: 1000, // IP당 최대 1000 요청 (일괄 처리 지원)
|
||||
message: {
|
||||
success: false,
|
||||
error: '너무 많은 요청입니다. 잠시 후 다시 시도해주세요.',
|
||||
code: 'RATE_LIMIT_EXCEEDED'
|
||||
},
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
// 인증된 사용자는 더 많은 요청 허용
|
||||
skip: (req) => {
|
||||
// Authorization 헤더가 있으면 Rate Limit 완화
|
||||
return req.headers.authorization && req.headers.authorization.startsWith('Bearer ');
|
||||
}
|
||||
});
|
||||
|
||||
// 로그인 시도 제한 (브루트포스 방지)
|
||||
const loginLimiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000, // 15분
|
||||
max: 10, // IP당 최대 10회 로그인 시도
|
||||
message: {
|
||||
success: false,
|
||||
error: '로그인 시도 횟수를 초과했습니다. 15분 후 다시 시도해주세요.',
|
||||
code: 'LOGIN_RATE_LIMIT_EXCEEDED'
|
||||
},
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false
|
||||
});
|
||||
|
||||
// Rate limiter 적용
|
||||
app.use('/api/', apiLimiter);
|
||||
app.use('/api/auth/login', loginLimiter);
|
||||
|
||||
logger.info('Rate Limiting 설정 완료');
|
||||
|
||||
// CSRF Protection (선택적 - 필요 시 주석 해제)
|
||||
// const { verifyCsrfToken, getCsrfToken } = require('../middlewares/csrf');
|
||||
//
|
||||
// CSRF 토큰 발급 엔드포인트
|
||||
// app.get('/api/csrf-token', getCsrfToken);
|
||||
//
|
||||
// CSRF 검증 미들웨어 (로그인 등 일부 경로 제외)
|
||||
// app.use('/api/', verifyCsrfToken({
|
||||
// ignorePaths: [
|
||||
// '/api/auth/login',
|
||||
// '/api/auth/register',
|
||||
// '/api/health',
|
||||
// '/api/csrf-token'
|
||||
// ]
|
||||
// }));
|
||||
//
|
||||
// logger.info('CSRF Protection 설정 완료');
|
||||
|
||||
logger.info('미들웨어 설정 완료');
|
||||
}
|
||||
|
||||
module.exports = setupMiddlewares;
|
||||
192
deploy/tkfb-package/api.hyungi.net/config/routes.js
Normal file
192
deploy/tkfb-package/api.hyungi.net/config/routes.js
Normal file
@@ -0,0 +1,192 @@
|
||||
/**
|
||||
* 라우트 설정
|
||||
*
|
||||
* 애플리케이션의 모든 라우트를 등록하는 중앙화된 설정 파일
|
||||
*
|
||||
* @author TK-FB-Project
|
||||
* @since 2025-12-11
|
||||
*/
|
||||
|
||||
const swaggerUi = require('swagger-ui-express');
|
||||
const swaggerSpec = require('./swagger');
|
||||
const { verifyToken } = require('../middlewares/authMiddleware');
|
||||
const { activityLogger } = require('../middlewares/activityLogger');
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
/**
|
||||
* 모든 라우트를 Express 앱에 등록
|
||||
* @param {Express.Application} app - Express 애플리케이션 인스턴스
|
||||
*/
|
||||
function setupRoutes(app) {
|
||||
// 라우터 가져오기
|
||||
const authRoutes = require('../routes/authRoutes');
|
||||
const projectRoutes = require('../routes/projectRoutes');
|
||||
const workerRoutes = require('../routes/workerRoutes');
|
||||
const workReportRoutes = require('../routes/workReportRoutes');
|
||||
const toolsRoute = require('../routes/toolsRoute');
|
||||
const uploadRoutes = require('../routes/uploadRoutes');
|
||||
const uploadBgRoutes = require('../routes/uploadBgRoutes');
|
||||
const dailyIssueReportRoutes = require('../routes/dailyIssueReportRoutes');
|
||||
const issueTypeRoutes = require('../routes/issueTypeRoutes');
|
||||
const healthRoutes = require('../routes/healthRoutes');
|
||||
const dailyWorkReportRoutes = require('../routes/dailyWorkReportRoutes');
|
||||
const workAnalysisRoutes = require('../routes/workAnalysisRoutes');
|
||||
const analysisRoutes = require('../routes/analysisRoutes');
|
||||
const systemRoutes = require('../routes/systemRoutes');
|
||||
const performanceRoutes = require('../routes/performanceRoutes');
|
||||
const userRoutes = require('../routes/userRoutes');
|
||||
const setupRoutes = require('../routes/setupRoutes');
|
||||
const workReportAnalysisRoutes = require('../routes/workReportAnalysisRoutes');
|
||||
const attendanceRoutes = require('../routes/attendanceRoutes');
|
||||
const monthlyStatusRoutes = require('../routes/monthlyStatusRoutes');
|
||||
const pageAccessRoutes = require('../routes/pageAccessRoutes');
|
||||
const workplaceRoutes = require('../routes/workplaceRoutes');
|
||||
const equipmentRoutes = require('../routes/equipmentRoutes');
|
||||
const taskRoutes = require('../routes/taskRoutes');
|
||||
const tbmRoutes = require('../routes/tbmRoutes');
|
||||
const vacationRequestRoutes = require('../routes/vacationRequestRoutes');
|
||||
const vacationTypeRoutes = require('../routes/vacationTypeRoutes');
|
||||
const vacationBalanceRoutes = require('../routes/vacationBalanceRoutes');
|
||||
const visitRequestRoutes = require('../routes/visitRequestRoutes');
|
||||
const workIssueRoutes = require('../routes/workIssueRoutes');
|
||||
const departmentRoutes = require('../routes/departmentRoutes');
|
||||
const patrolRoutes = require('../routes/patrolRoutes');
|
||||
const notificationRoutes = require('../routes/notificationRoutes');
|
||||
const notificationRecipientRoutes = require('../routes/notificationRecipientRoutes');
|
||||
|
||||
// Rate Limiters 설정
|
||||
const rateLimit = require('express-rate-limit');
|
||||
|
||||
const loginLimiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000, // 15분
|
||||
max: 5, // 최대 5회
|
||||
message: '너무 많은 로그인 시도가 있었습니다. 잠시 후 다시 시도해주세요.',
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false
|
||||
});
|
||||
|
||||
const apiLimiter = rateLimit({
|
||||
windowMs: 1 * 60 * 1000, // 1분
|
||||
max: 1000, // 최대 1000회 (기존 100회에서 대폭 증가)
|
||||
message: 'API 요청 한도를 초과했습니다. 잠시 후 다시 시도해주세요.',
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
// 관리자 및 시스템 계정은 rate limit 제외
|
||||
skip: (req) => {
|
||||
// 인증된 사용자 정보 확인
|
||||
if (req.user && (req.user.access_level === 'system' || req.user.access_level === 'admin')) {
|
||||
return true; // rate limit 건너뛰기
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// 모든 API 요청에 활동 로거 적용
|
||||
app.use('/api/*', activityLogger);
|
||||
|
||||
// 인증 불필요 경로 - 로그인
|
||||
app.use('/api/auth', loginLimiter, authRoutes);
|
||||
|
||||
// DB 설정 라우트 (개발용)
|
||||
app.use('/api/setup', setupRoutes);
|
||||
|
||||
// Health check
|
||||
app.use('/api/health', healthRoutes);
|
||||
|
||||
// 인증이 필요 없는 공개 경로 목록
|
||||
const publicPaths = [
|
||||
'/api/auth/login',
|
||||
'/api/auth/refresh-token',
|
||||
'/api/auth/check-password-strength',
|
||||
'/api/health',
|
||||
'/api/ping',
|
||||
'/api/status',
|
||||
'/api/setup/setup-attendance-db',
|
||||
'/api/setup/setup-monthly-status',
|
||||
'/api/setup/add-overtime-warning',
|
||||
'/api/setup/migrate-existing-data',
|
||||
'/api/setup/check-data-status',
|
||||
'/api/monthly-status/calendar',
|
||||
'/api/monthly-status/daily-details',
|
||||
'/api/migrate-work-type-id', // 임시 마이그레이션 - 실행 후 삭제!
|
||||
'/api/diagnose-work-type-id', // 임시 진단 - 실행 후 삭제!
|
||||
'/api/test-analysis' // 임시 분석 테스트 - 실행 후 삭제!
|
||||
];
|
||||
|
||||
// 인증 미들웨어 - 공개 경로를 제외한 모든 API (rate limiter보다 먼저 실행)
|
||||
app.use('/api/*', (req, res, next) => {
|
||||
const isPublicPath = publicPaths.some(path => {
|
||||
return req.originalUrl === path ||
|
||||
req.originalUrl.startsWith(path + '?') ||
|
||||
req.originalUrl.startsWith(path + '/');
|
||||
});
|
||||
|
||||
if (isPublicPath) {
|
||||
logger.debug('공개 경로 허용', { url: req.originalUrl });
|
||||
return next();
|
||||
}
|
||||
|
||||
logger.debug('인증 필요 경로', { url: req.originalUrl });
|
||||
verifyToken(req, res, next);
|
||||
});
|
||||
|
||||
// 인증 후 일반 API에 속도 제한 적용 (인증된 사용자 정보로 skip 판단)
|
||||
app.use('/api/', apiLimiter);
|
||||
|
||||
// 인증된 사용자만 접근 가능한 라우트들
|
||||
app.use('/api/issue-reports', dailyIssueReportRoutes);
|
||||
app.use('/api/issue-types', issueTypeRoutes);
|
||||
app.use('/api/workers', workerRoutes);
|
||||
app.use('/api/daily-work-reports', dailyWorkReportRoutes);
|
||||
app.use('/api/work-analysis', workAnalysisRoutes);
|
||||
app.use('/api/analysis', analysisRoutes);
|
||||
app.use('/api/daily-work-reports-analysis', workReportAnalysisRoutes);
|
||||
app.use('/api/attendance', attendanceRoutes);
|
||||
app.use('/api/monthly-status', monthlyStatusRoutes);
|
||||
app.use('/api/workreports', workReportRoutes);
|
||||
app.use('/api/system', systemRoutes);
|
||||
app.use('/api/uploads', uploadRoutes);
|
||||
app.use('/api/performance', performanceRoutes);
|
||||
app.use('/api/projects', projectRoutes);
|
||||
app.use('/api/tools', toolsRoute);
|
||||
app.use('/api/users', userRoutes);
|
||||
app.use('/api/workplaces', workplaceRoutes);
|
||||
app.use('/api/equipments', equipmentRoutes);
|
||||
app.use('/api/tasks', taskRoutes);
|
||||
app.use('/api/vacation-requests', vacationRequestRoutes); // 휴가 신청 관리
|
||||
app.use('/api/vacation-types', vacationTypeRoutes); // 휴가 유형 관리
|
||||
app.use('/api/vacation-balances', vacationBalanceRoutes); // 휴가 잔액 관리
|
||||
app.use('/api/workplace-visits', visitRequestRoutes); // 출입 신청 및 안전교육 관리
|
||||
app.use('/api', pageAccessRoutes); // 페이지 접근 권한 관리
|
||||
app.use('/api/tbm', tbmRoutes); // TBM 시스템
|
||||
app.use('/api/work-issues', workIssueRoutes); // 문제 신고 시스템
|
||||
app.use('/api/departments', departmentRoutes); // 부서 관리
|
||||
app.use('/api/patrol', patrolRoutes); // 일일순회점검 시스템
|
||||
app.use('/api/notifications', notificationRoutes); // 알림 시스템
|
||||
app.use('/api/notification-recipients', notificationRecipientRoutes); // 알림 수신자 설정
|
||||
app.use('/api', uploadBgRoutes);
|
||||
|
||||
// Swagger API 문서
|
||||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec, {
|
||||
explorer: true,
|
||||
customCss: '.swagger-ui .topbar { display: none }',
|
||||
customSiteTitle: 'TK Work Management API',
|
||||
swaggerOptions: {
|
||||
persistAuthorization: true,
|
||||
displayRequestDuration: true,
|
||||
docExpansion: 'none',
|
||||
filter: true,
|
||||
showExtensions: true,
|
||||
showCommonExtensions: true
|
||||
}
|
||||
}));
|
||||
|
||||
app.get('/api-docs.json', (req, res) => {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(swaggerSpec);
|
||||
});
|
||||
|
||||
logger.info('라우트 설정 완료');
|
||||
}
|
||||
|
||||
module.exports = setupRoutes;
|
||||
101
deploy/tkfb-package/api.hyungi.net/config/security.js
Normal file
101
deploy/tkfb-package/api.hyungi.net/config/security.js
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* 보안 설정 (Helmet)
|
||||
*
|
||||
* HTTP 헤더 보안 설정
|
||||
*
|
||||
* @author TK-FB-Project
|
||||
* @since 2025-12-11
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helmet 보안 설정 옵션
|
||||
*/
|
||||
const helmetOptions = {
|
||||
/**
|
||||
* Content Security Policy
|
||||
* XSS 공격 방지
|
||||
*/
|
||||
contentSecurityPolicy: {
|
||||
directives: {
|
||||
defaultSrc: ["'self'"],
|
||||
styleSrc: ["'self'", "'unsafe-inline'", "https://fonts.googleapis.com"],
|
||||
scriptSrc: ["'self'", "'unsafe-inline'", "'unsafe-eval'"], // 개발 중 unsafe-eval 허용
|
||||
imgSrc: ["'self'", "data:", "https:", "blob:"],
|
||||
fontSrc: ["'self'", "https://fonts.gstatic.com"],
|
||||
connectSrc: ["'self'", "https://api.technicalkorea.com"],
|
||||
frameSrc: ["'none'"],
|
||||
objectSrc: ["'none'"]
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* HTTP Strict Transport Security (HSTS)
|
||||
* HTTPS 강제 사용
|
||||
*/
|
||||
hsts: {
|
||||
maxAge: 31536000, // 1년
|
||||
includeSubDomains: true,
|
||||
preload: true
|
||||
},
|
||||
|
||||
/**
|
||||
* X-Frame-Options
|
||||
* 클릭재킹 공격 방지
|
||||
*/
|
||||
frameguard: {
|
||||
action: 'deny'
|
||||
},
|
||||
|
||||
/**
|
||||
* X-Content-Type-Options
|
||||
* MIME 타입 스니핑 방지
|
||||
*/
|
||||
noSniff: true,
|
||||
|
||||
/**
|
||||
* X-XSS-Protection
|
||||
* XSS 필터 활성화
|
||||
*/
|
||||
xssFilter: true,
|
||||
|
||||
/**
|
||||
* Referrer-Policy
|
||||
* 리퍼러 정보 제어
|
||||
*/
|
||||
referrerPolicy: {
|
||||
policy: 'strict-origin-when-cross-origin'
|
||||
},
|
||||
|
||||
/**
|
||||
* X-DNS-Prefetch-Control
|
||||
* DNS prefetching 제어
|
||||
*/
|
||||
dnsPrefetchControl: {
|
||||
allow: false
|
||||
},
|
||||
|
||||
/**
|
||||
* X-Download-Options
|
||||
* IE8+ 다운로드 옵션
|
||||
*/
|
||||
ieNoOpen: true,
|
||||
|
||||
/**
|
||||
* X-Permitted-Cross-Domain-Policies
|
||||
* Adobe 제품의 크로스 도메인 정책
|
||||
*/
|
||||
permittedCrossDomainPolicies: {
|
||||
permittedPolicies: 'none'
|
||||
},
|
||||
|
||||
/**
|
||||
* Cross-Origin-Resource-Policy
|
||||
* 크로스 오리진 리소스 공유 설정
|
||||
* 이미지 등 정적 파일을 다른 포트에서 로드할 수 있도록 허용
|
||||
*/
|
||||
crossOriginResourcePolicy: {
|
||||
policy: 'cross-origin'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = helmetOptions;
|
||||
497
deploy/tkfb-package/api.hyungi.net/config/swagger.js
Normal file
497
deploy/tkfb-package/api.hyungi.net/config/swagger.js
Normal file
@@ -0,0 +1,497 @@
|
||||
// config/swagger.js - Swagger/OpenAPI 설정
|
||||
|
||||
const swaggerJSDoc = require('swagger-jsdoc');
|
||||
|
||||
const swaggerDefinition = {
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
title: 'Technical Korea Work Management API',
|
||||
version: '2.1.0',
|
||||
description: '보안이 강화된 생산관리 시스템 API - 작업자, 프로젝트, 일일 작업 보고서 관리',
|
||||
contact: {
|
||||
name: 'Technical Korea',
|
||||
email: 'admin@technicalkorea.com'
|
||||
},
|
||||
license: {
|
||||
name: 'MIT',
|
||||
url: 'https://opensource.org/licenses/MIT'
|
||||
}
|
||||
},
|
||||
servers: [
|
||||
{
|
||||
url: 'http://localhost:20005',
|
||||
description: '개발 서버 (Docker)'
|
||||
},
|
||||
{
|
||||
url: 'http://localhost:3005',
|
||||
description: '로컬 개발 서버'
|
||||
}
|
||||
],
|
||||
components: {
|
||||
securitySchemes: {
|
||||
bearerAuth: {
|
||||
type: 'http',
|
||||
scheme: 'bearer',
|
||||
bearerFormat: 'JWT',
|
||||
description: 'JWT 토큰을 사용한 인증. 로그인 후 받은 토큰을 "Bearer {token}" 형식으로 입력하세요.'
|
||||
}
|
||||
},
|
||||
schemas: {
|
||||
// 공통 응답 스키마
|
||||
SuccessResponse: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: {
|
||||
type: 'boolean',
|
||||
example: true
|
||||
},
|
||||
message: {
|
||||
type: 'string',
|
||||
example: '요청이 성공적으로 처리되었습니다.'
|
||||
},
|
||||
data: {
|
||||
type: 'object',
|
||||
description: '응답 데이터'
|
||||
},
|
||||
timestamp: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
example: '2024-01-01T00:00:00.000Z'
|
||||
}
|
||||
}
|
||||
},
|
||||
ErrorResponse: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: {
|
||||
type: 'boolean',
|
||||
example: false
|
||||
},
|
||||
error: {
|
||||
type: 'string',
|
||||
example: '오류 메시지'
|
||||
},
|
||||
timestamp: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
example: '2024-01-01T00:00:00.000Z'
|
||||
}
|
||||
}
|
||||
},
|
||||
PaginatedResponse: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: {
|
||||
type: 'boolean',
|
||||
example: true
|
||||
},
|
||||
message: {
|
||||
type: 'string',
|
||||
example: '데이터 조회 성공'
|
||||
},
|
||||
data: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object'
|
||||
}
|
||||
},
|
||||
meta: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
pagination: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
currentPage: { type: 'integer', example: 1 },
|
||||
totalPages: { type: 'integer', example: 10 },
|
||||
totalCount: { type: 'integer', example: 100 },
|
||||
limit: { type: 'integer', example: 10 },
|
||||
hasNextPage: { type: 'boolean', example: true },
|
||||
hasPrevPage: { type: 'boolean', example: false }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
timestamp: {
|
||||
type: 'string',
|
||||
format: 'date-time'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 사용자 관련 스키마
|
||||
User: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '사용자 ID'
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
example: 'admin',
|
||||
description: '사용자명'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
example: '관리자',
|
||||
description: '실명'
|
||||
},
|
||||
email: {
|
||||
type: 'string',
|
||||
format: 'email',
|
||||
example: 'admin@technicalkorea.com',
|
||||
description: '이메일 주소'
|
||||
},
|
||||
role: {
|
||||
type: 'string',
|
||||
example: 'admin',
|
||||
description: '역할'
|
||||
},
|
||||
access_level: {
|
||||
type: 'string',
|
||||
enum: ['user', 'admin', 'system'],
|
||||
example: 'admin',
|
||||
description: '접근 권한 레벨'
|
||||
},
|
||||
worker_id: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '연결된 작업자 ID'
|
||||
},
|
||||
is_active: {
|
||||
type: 'boolean',
|
||||
example: true,
|
||||
description: '활성 상태'
|
||||
},
|
||||
last_login_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '마지막 로그인 시간'
|
||||
},
|
||||
created_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '생성 시간'
|
||||
},
|
||||
updated_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '수정 시간'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 작업자 관련 스키마
|
||||
Worker: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
worker_id: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '작업자 ID'
|
||||
},
|
||||
worker_name: {
|
||||
type: 'string',
|
||||
example: '김철수',
|
||||
description: '작업자 이름'
|
||||
},
|
||||
position: {
|
||||
type: 'string',
|
||||
example: '용접공',
|
||||
description: '직책'
|
||||
},
|
||||
department: {
|
||||
type: 'string',
|
||||
example: '생산부',
|
||||
description: '부서'
|
||||
},
|
||||
phone: {
|
||||
type: 'string',
|
||||
example: '010-1234-5678',
|
||||
description: '전화번호'
|
||||
},
|
||||
email: {
|
||||
type: 'string',
|
||||
format: 'email',
|
||||
example: 'worker@technicalkorea.com',
|
||||
description: '이메일'
|
||||
},
|
||||
hire_date: {
|
||||
type: 'string',
|
||||
format: 'date',
|
||||
example: '2024-01-01',
|
||||
description: '입사일'
|
||||
},
|
||||
is_active: {
|
||||
type: 'boolean',
|
||||
example: true,
|
||||
description: '활성 상태'
|
||||
},
|
||||
created_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '생성 시간'
|
||||
},
|
||||
updated_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '수정 시간'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 프로젝트 관련 스키마
|
||||
Project: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
project_id: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '프로젝트 ID'
|
||||
},
|
||||
project_name: {
|
||||
type: 'string',
|
||||
example: '신규 플랜트 건설',
|
||||
description: '프로젝트 이름'
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
example: '대형 화학 플랜트 건설 프로젝트',
|
||||
description: '프로젝트 설명'
|
||||
},
|
||||
start_date: {
|
||||
type: 'string',
|
||||
format: 'date',
|
||||
example: '2024-01-01',
|
||||
description: '시작일'
|
||||
},
|
||||
end_date: {
|
||||
type: 'string',
|
||||
format: 'date',
|
||||
example: '2024-12-31',
|
||||
description: '종료일'
|
||||
},
|
||||
status: {
|
||||
type: 'string',
|
||||
example: 'active',
|
||||
description: '프로젝트 상태'
|
||||
},
|
||||
created_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '생성 시간'
|
||||
},
|
||||
updated_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '수정 시간'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 작업 관련 스키마
|
||||
Task: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
task_id: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '작업 ID'
|
||||
},
|
||||
task_name: {
|
||||
type: 'string',
|
||||
example: '용접 작업',
|
||||
description: '작업 이름'
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
example: '파이프 용접 작업',
|
||||
description: '작업 설명'
|
||||
},
|
||||
category: {
|
||||
type: 'string',
|
||||
example: '용접',
|
||||
description: '작업 카테고리'
|
||||
},
|
||||
is_active: {
|
||||
type: 'boolean',
|
||||
example: true,
|
||||
description: '활성 상태'
|
||||
},
|
||||
created_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '생성 시간'
|
||||
},
|
||||
updated_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '수정 시간'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 일일 작업 보고서 관련 스키마
|
||||
DailyWorkReport: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '보고서 ID'
|
||||
},
|
||||
report_date: {
|
||||
type: 'string',
|
||||
format: 'date',
|
||||
example: '2024-01-01',
|
||||
description: '작업 날짜'
|
||||
},
|
||||
worker_id: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '작업자 ID'
|
||||
},
|
||||
project_id: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '프로젝트 ID'
|
||||
},
|
||||
work_type_id: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '작업 유형 ID'
|
||||
},
|
||||
work_status_id: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '작업 상태 ID (1:정규, 2:에러)'
|
||||
},
|
||||
error_type_id: {
|
||||
type: 'integer',
|
||||
example: null,
|
||||
description: '에러 유형 ID (에러일 때만)'
|
||||
},
|
||||
work_hours: {
|
||||
type: 'number',
|
||||
format: 'decimal',
|
||||
example: 8.5,
|
||||
description: '작업 시간'
|
||||
},
|
||||
created_by: {
|
||||
type: 'integer',
|
||||
example: 1,
|
||||
description: '작성자 user_id'
|
||||
},
|
||||
created_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '생성 시간'
|
||||
},
|
||||
updated_at: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
description: '수정 시간'
|
||||
},
|
||||
// 조인된 데이터
|
||||
worker_name: {
|
||||
type: 'string',
|
||||
example: '김철수',
|
||||
description: '작업자 이름'
|
||||
},
|
||||
project_name: {
|
||||
type: 'string',
|
||||
example: '신규 플랜트 건설',
|
||||
description: '프로젝트 이름'
|
||||
},
|
||||
work_type_name: {
|
||||
type: 'string',
|
||||
example: '용접',
|
||||
description: '작업 유형 이름'
|
||||
},
|
||||
work_status_name: {
|
||||
type: 'string',
|
||||
example: '정규',
|
||||
description: '작업 상태 이름'
|
||||
},
|
||||
error_type_name: {
|
||||
type: 'string',
|
||||
example: null,
|
||||
description: '에러 유형 이름'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 로그인 관련 스키마
|
||||
LoginRequest: {
|
||||
type: 'object',
|
||||
required: ['username', 'password'],
|
||||
properties: {
|
||||
username: {
|
||||
type: 'string',
|
||||
example: 'admin',
|
||||
description: '사용자명'
|
||||
},
|
||||
password: {
|
||||
type: 'string',
|
||||
example: 'password123',
|
||||
description: '비밀번호'
|
||||
}
|
||||
}
|
||||
},
|
||||
LoginResponse: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: {
|
||||
type: 'boolean',
|
||||
example: true
|
||||
},
|
||||
message: {
|
||||
type: 'string',
|
||||
example: '로그인 성공'
|
||||
},
|
||||
data: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user: {
|
||||
$ref: '#/components/schemas/User'
|
||||
},
|
||||
token: {
|
||||
type: 'string',
|
||||
example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
||||
description: 'JWT 토큰'
|
||||
},
|
||||
redirectUrl: {
|
||||
type: 'string',
|
||||
example: '/pages/dashboard/group-leader.html',
|
||||
description: '리다이렉트 URL'
|
||||
}
|
||||
}
|
||||
},
|
||||
timestamp: {
|
||||
type: 'string',
|
||||
format: 'date-time'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
security: [
|
||||
{
|
||||
bearerAuth: []
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const options = {
|
||||
definition: swaggerDefinition,
|
||||
apis: [
|
||||
'./routes/*.js',
|
||||
'./controllers/*.js',
|
||||
'./index.js'
|
||||
]
|
||||
};
|
||||
|
||||
const swaggerSpec = swaggerJSDoc(options);
|
||||
|
||||
module.exports = swaggerSpec;
|
||||
Reference in New Issue
Block a user