신규 독립 시스템 tkpurchase (구매/방문 관리) 구축: - 협력업체 CRUD + 소속 작업자 관리 (마스터 데이터 소유) - 당일 방문 등록/체크인/체크아웃 + 일괄 마감 - 업체 자동완성, CSV 내보내기, 집계 통계 - 자정 자동 체크아웃 (node-cron) - tkuser 협력업체 읽기 전용 탭 + 권한 그리드(tkpurchase-perms) 추가 - docker-compose에 tkpurchase-api/web 서비스 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
81 lines
2.6 KiB
JavaScript
81 lines
2.6 KiB
JavaScript
/**
|
|
* tkuser-api - 사용자 관리 서비스
|
|
*
|
|
* 사용자 CRUD + 페이지 권한 관리 통합 API
|
|
* MariaDB (sso_users + user_page_permissions) 직접 연결
|
|
*/
|
|
|
|
const express = require('express');
|
|
const path = require('path');
|
|
const cors = require('cors');
|
|
const userRoutes = require('./routes/userRoutes');
|
|
const permissionRoutes = require('./routes/permissionRoutes');
|
|
const projectRoutes = require('./routes/projectRoutes');
|
|
const workerRoutes = require('./routes/workerRoutes');
|
|
const departmentRoutes = require('./routes/departmentRoutes');
|
|
const workplaceRoutes = require('./routes/workplaceRoutes');
|
|
const equipmentRoutes = require('./routes/equipmentRoutes');
|
|
const taskRoutes = require('./routes/taskRoutes');
|
|
const vacationRoutes = require('./routes/vacationRoutes');
|
|
const partnerRoutes = require('./routes/partnerRoutes');
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
const allowedOrigins = [
|
|
'https://tkfb.technicalkorea.net',
|
|
'https://tkreport.technicalkorea.net',
|
|
'https://tkqc.technicalkorea.net',
|
|
'https://tkuser.technicalkorea.net',
|
|
'https://tkpurchase.technicalkorea.net',
|
|
];
|
|
if (process.env.NODE_ENV === 'development') {
|
|
allowedOrigins.push('http://localhost:30080', 'http://localhost:30180', 'http://localhost:30280');
|
|
}
|
|
app.use(cors({
|
|
origin: function(origin, cb) {
|
|
if (!origin || allowedOrigins.includes(origin) || /^http:\/\/192\.168\.\d+\.\d+(:\d+)?$/.test(origin)) return cb(null, true);
|
|
cb(new Error('CORS blocked: ' + origin));
|
|
},
|
|
credentials: true
|
|
}));
|
|
app.use(express.json());
|
|
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
|
|
|
|
// Health check
|
|
app.get('/health', (req, res) => {
|
|
res.json({ status: 'ok', service: 'tkuser-api', timestamp: new Date().toISOString() });
|
|
});
|
|
|
|
// Routes
|
|
app.use('/api/users', userRoutes);
|
|
app.use('/api/permissions', permissionRoutes);
|
|
app.use('/api/projects', projectRoutes);
|
|
app.use('/api/workers', workerRoutes);
|
|
app.use('/api/departments', departmentRoutes);
|
|
app.use('/api/workplaces', workplaceRoutes);
|
|
app.use('/api/equipments', equipmentRoutes);
|
|
app.use('/api/tasks', taskRoutes);
|
|
app.use('/api/vacations', vacationRoutes);
|
|
app.use('/api/partners', partnerRoutes);
|
|
|
|
// 404
|
|
app.use((req, res) => {
|
|
res.status(404).json({ success: false, error: 'Not Found' });
|
|
});
|
|
|
|
// Error handler
|
|
app.use((err, req, res, next) => {
|
|
console.error('tkuser-api Error:', err.message);
|
|
res.status(err.status || 500).json({
|
|
success: false,
|
|
error: err.message || 'Internal Server Error'
|
|
});
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`tkuser-api running on port ${PORT}`);
|
|
});
|
|
|
|
module.exports = app;
|