Phase 1: tkuser 협력업체 CRUD 이관 (읽기전용 → 전체 CRUD) Phase 2: tkpurchase 개편 — 일용공 신청/확정, 작업일정, 업무현황, 계정관리, 협력업체 포털 Phase 3: tksafety 신규 시스템 — 방문관리 + 안전교육 신고 Phase 4: SSO 인증 보강 (partner_company_id JWT, 만료일 체크), 권한 테이블 기반 접근 제어 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
66 lines
2.0 KiB
JavaScript
66 lines
2.0 KiB
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
const cron = require('node-cron');
|
|
const partnerRoutes = require('./routes/partnerRoutes');
|
|
const dayLaborRoutes = require('./routes/dayLaborRoutes');
|
|
const scheduleRoutes = require('./routes/scheduleRoutes');
|
|
const checkinRoutes = require('./routes/checkinRoutes');
|
|
const workReportRoutes = require('./routes/workReportRoutes');
|
|
const partnerAccountRoutes = require('./routes/partnerAccountRoutes');
|
|
|
|
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',
|
|
'https://tksafety.technicalkorea.net',
|
|
];
|
|
if (process.env.NODE_ENV === 'development') {
|
|
allowedOrigins.push('http://localhost:30080', 'http://localhost:30480');
|
|
}
|
|
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());
|
|
|
|
// Health check
|
|
app.get('/health', (req, res) => {
|
|
res.json({ status: 'ok', service: 'tkpurchase-api', timestamp: new Date().toISOString() });
|
|
});
|
|
|
|
// Routes
|
|
app.use('/api/partners', partnerRoutes);
|
|
app.use('/api/day-labor', dayLaborRoutes);
|
|
app.use('/api/schedules', scheduleRoutes);
|
|
app.use('/api/checkins', checkinRoutes);
|
|
app.use('/api/work-reports', workReportRoutes);
|
|
app.use('/api/partner-accounts', partnerAccountRoutes);
|
|
|
|
// 404
|
|
app.use((req, res) => {
|
|
res.status(404).json({ success: false, error: 'Not Found' });
|
|
});
|
|
|
|
// Error handler
|
|
app.use((err, req, res, next) => {
|
|
console.error('tkpurchase-api Error:', err.message);
|
|
res.status(err.status || 500).json({
|
|
success: false,
|
|
error: err.message || 'Internal Server Error'
|
|
});
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`tkpurchase-api running on port ${PORT}`);
|
|
});
|
|
|
|
module.exports = app;
|