refactor: cleanup temp files, centralize API URL, and dynamic routing
- 불필요한 마이그레이션 스크립트, JSON 덤프, 백업 폴더 일괄 삭제 - 프론트엔드 API_BASE_URL 상수 도입 및 하드코딩된 API 엔드포인트 통합 - 백엔드(server.js) GET/POST 라우팅 구조를 Map 기반 동적 라우팅으로 리팩토링 - 미사용 dummyDataGenerator 제거
This commit is contained in:
@@ -5,6 +5,7 @@ import { generateOptionsHTML, setEditLock } from './ModalUtils';
|
||||
import { createIcons, X, Save, Database, CalendarClock, Edit2 } from 'lucide';
|
||||
import { formatExcelDate } from '../../core/excelHandler';
|
||||
import { UI_TEXT } from '../../core/schema';
|
||||
import { API_BASE_URL } from '../../core/utils';
|
||||
|
||||
let currentItem: any = null;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { openSwUserModal } from './SWUserModal';
|
||||
import { createIcons, History, Plus, X, Save, Edit2, RotateCcw, Calendar } from 'lucide';
|
||||
import { CORP_LIST } from './SharedData';
|
||||
import { ASSET_SCHEMA, UI_TEXT } from '../../core/schema';
|
||||
import { API_BASE_URL } from '../../core/utils';
|
||||
import {
|
||||
generateOptionsHTML,
|
||||
setFieldValue,
|
||||
@@ -433,7 +434,7 @@ export function initSwModal(onSave: () => void, closeModals: () => void) {
|
||||
};
|
||||
|
||||
// Call generic API for logs (could be added to state.ts)
|
||||
await fetch(`http://${location.hostname}:3000/api/asset/history/batch`, {
|
||||
await fetch(`${API_BASE_URL}/api/asset/history/batch`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify([...state.masterData.logs, log])
|
||||
|
||||
@@ -1,200 +0,0 @@
|
||||
import { MasterAssetData, HardwareAsset, SoftwareAsset, SWUser } from './excelHandler';
|
||||
|
||||
const corps = ['한맥', '삼안', '바론'];
|
||||
const users = ['홍길동', '김철수', '이영희', '박지훈', '김팀장', '신유진', '윤대웅', '마리아'];
|
||||
const depts = ['설계팀', '기술팀', '경영지원팀', '영업팀'];
|
||||
|
||||
function rand(arr: any[]) {
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
}
|
||||
|
||||
function randDate(startYear: number, endYear: number) {
|
||||
const y = Math.floor(Math.random() * (endYear - startYear + 1)) + startYear;
|
||||
const m = String(Math.floor(Math.random() * 12) + 1).padStart(2, '0');
|
||||
const d = String(Math.floor(Math.random() * 28) + 1).padStart(2, '0');
|
||||
return `${y}-${m}-${d}`;
|
||||
}
|
||||
|
||||
function randUser() { // 25% 확률로 유휴자산 할당
|
||||
return Math.random() < 0.25 ? '' : rand(users);
|
||||
}
|
||||
|
||||
export function generateDummyData(): MasterAssetData {
|
||||
const pc: HardwareAsset[] = [];
|
||||
const server: HardwareAsset[] = [];
|
||||
const storage: HardwareAsset[] = [];
|
||||
const equip: HardwareAsset[] = [];
|
||||
const mobile: HardwareAsset[] = [];
|
||||
const subSw: SoftwareAsset[] = [];
|
||||
const permSw: SoftwareAsset[] = [];
|
||||
const swUsers: any[] = [];
|
||||
const logs: any[] = [];
|
||||
|
||||
// 1. 개인PC 50개
|
||||
for (let i = 1; i <= 50; i++) {
|
||||
const purchaseYear = Math.floor(Math.random() * 10) + 2017;
|
||||
pc.push({
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
type: '개인PC',
|
||||
법인: rand(corps),
|
||||
자산코드: `HM-PC-${purchaseYear}-${String(i).padStart(3, '0')}`,
|
||||
명칭: '',
|
||||
위치: `${rand(['본사', '지사'])} ${Math.floor(Math.random()*5)+1}층`,
|
||||
사용자: randUser(),
|
||||
CPU: rand(['i5-10400', 'i7-12700', 'Ryzen 5', 'Ryzen 7']),
|
||||
GPU: rand(['-', 'GTX 1660', 'RTX 3060', 'RTX 4070']),
|
||||
RAM: rand(['16GB', '32GB']),
|
||||
SSD1: rand(['256GB', '512GB', '1TB']),
|
||||
SSD2: '',
|
||||
HDD1: rand(['-', '1TB', '2TB']),
|
||||
HDD2: '',
|
||||
구매일: randDate(purchaseYear, purchaseYear),
|
||||
금액: String(Math.floor(Math.random()*100 + 50) * 10000).replace(/\B(?=(\d{3})+(?!\d))/g, ','),
|
||||
구매업체: rand(['다나와', '컴퓨존', '오피스디포']),
|
||||
품의서명: '',
|
||||
관리자: '', IP주소: '', MACaddress: '', OS: '', HW사양: ''
|
||||
});
|
||||
}
|
||||
|
||||
// 2. 서버 20개
|
||||
for (let i = 1; i <= 20; i++) {
|
||||
const purchaseYear = Math.floor(Math.random() * 10) + 2017;
|
||||
server.push({
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
type: '서버',
|
||||
법인: rand(corps),
|
||||
자산코드: `HM-SV-${purchaseYear}-${String(i).padStart(3, '0')}`,
|
||||
명칭: `웹/DB 서버 #${i}`,
|
||||
용도: rand(['웹 서버', 'DB 서버', '백업 서버', '개발 서버']),
|
||||
storage유형: rand(['물리', 'VM']),
|
||||
위치: rand(['IDC 1센터', 'IDC 2센터', '본사 전산실']),
|
||||
관리자: rand(users),
|
||||
담당자_정: rand(users),
|
||||
담당자_부: rand(users),
|
||||
IP주소: `192.168.10.${i}`,
|
||||
원격접속: `ssh://192.168.10.${i}:22`,
|
||||
MACaddress: '00:11:22:33:44:' + String(i).padStart(2, '0'),
|
||||
OS: rand(['Windows Server 2019', 'Ubuntu 22.04 LTS', 'CentOS 7']),
|
||||
모델명: rand(['Dell PowerEdge R740', 'HP ProLiant DL380', 'Lenovo ThinkSystem']),
|
||||
CPU: rand(['Xeon Silver 4210', 'Xeon Gold 6248', 'EPYC 7702']),
|
||||
RAM: rand(['64GB', '128GB', '256GB']),
|
||||
GPU: rand(['-', 'RTX A4000', 'Tesla V100']),
|
||||
SSD1: rand(['512GB SSD', '1TB NVMe']),
|
||||
SSD2: rand(['-', '1TB SSD', '2TB SSD']),
|
||||
HDD1: rand(['-', '4TB HDD', '8TB HDD']),
|
||||
모니터링: rand(['Zabbix', 'Grafana', 'PRTG']),
|
||||
비고: i % 5 === 0 ? '정기 점검 대상' : '-',
|
||||
HW사양: 'Xeon 16Core, 64GB RAM',
|
||||
구매일: randDate(purchaseYear, purchaseYear),
|
||||
금액: '5,000,000',
|
||||
구매업체: '서버뱅크',
|
||||
품의서명: ''
|
||||
});
|
||||
}
|
||||
|
||||
// 3. 스토리지 10개
|
||||
for (let i = 1; i <= 10; i++) {
|
||||
const purchaseYear = Math.floor(Math.random() * 10) + 2017;
|
||||
storage.push({
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
type: '스토리지',
|
||||
법인: rand(corps),
|
||||
storage유형: rand(['NAS', 'DAS']),
|
||||
자산코드: `HM-ST-${purchaseYear}-${String(i).padStart(3, '0')}`,
|
||||
명칭: `백업 스토리지 #${i}`,
|
||||
위치: '전산실',
|
||||
모델명: rand(['Synology DS920+', 'QNAP TS-453D']),
|
||||
용량: rand(['16TB', '32TB', '64TB']),
|
||||
담당자_정: randUser(),
|
||||
담당자_부: rand(users),
|
||||
IP주소: `192.168.20.${i}`,
|
||||
MACaddress: '',
|
||||
구매일: randDate(purchaseYear, purchaseYear),
|
||||
금액: '1,500,000',
|
||||
구매업체: '스토리지넷',
|
||||
품의서명: '',
|
||||
관리자: '', OS: '', HW사양: ''
|
||||
});
|
||||
}
|
||||
|
||||
// 4. 전산비품 15개
|
||||
for (let i = 1; i <= 15; i++) {
|
||||
const purchaseYear = Math.floor(Math.random() * 8) + 2019;
|
||||
equip.push({
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
type: '전산비품',
|
||||
법인: rand(corps),
|
||||
비품유형: rand(['프린터', '모니터', 'UPS']),
|
||||
자산코드: `HM-EQ-${purchaseYear}-${String(i).padStart(3, '0')}`,
|
||||
명칭: `비품 #${i}`,
|
||||
위치: rand(['본사', '지사']),
|
||||
관리자: randUser(),
|
||||
구매일: randDate(purchaseYear, purchaseYear),
|
||||
금액: '300,000',
|
||||
구매업체: '오피스공구',
|
||||
품의서명: '',
|
||||
IP주소: '', MACaddress: '', OS: '', HW사양: ''
|
||||
});
|
||||
}
|
||||
|
||||
// 5. 모바일기기 10개
|
||||
for (let i = 1; i <= 10; i++) {
|
||||
const purchaseYear = Math.floor(Math.random() * 5) + 2022;
|
||||
mobile.push({
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
type: '모바일기기',
|
||||
법인: rand(corps),
|
||||
자산코드: `HM-MO-${purchaseYear}-${String(i).padStart(3, '0')}`,
|
||||
명칭: rand(['아이폰 15', '갤럭시 S24', '아이패드 에어']),
|
||||
위치: '개인 지급',
|
||||
관리자: randUser(),
|
||||
OS: rand(['iOS', 'Android', 'iPadOS']),
|
||||
구매일: randDate(purchaseYear, purchaseYear),
|
||||
금액: '1,200,000',
|
||||
구매업체: '통신사',
|
||||
품의서명: '',
|
||||
IP주소: '', MACaddress: '', HW사양: '', 비고: ''
|
||||
});
|
||||
}
|
||||
|
||||
// 6. 구독 SW 20개
|
||||
for (let i = 1; i <= 20; i++) {
|
||||
const swId = Math.random().toString(36).substring(2, 9);
|
||||
subSw.push({
|
||||
id: swId,
|
||||
type: '구독SW',
|
||||
분야: rand(['업무공통', '개발S/W']),
|
||||
법인: rand(corps),
|
||||
제품명: rand(['Adobe CC', 'M365']),
|
||||
구매일: '2024-01-01',
|
||||
만료일: '2025-01-01',
|
||||
금액: '100,000',
|
||||
수량: 5,
|
||||
계정명: `admin${i}@hm.com`,
|
||||
구매업체: '총판',
|
||||
비고: ''
|
||||
});
|
||||
swUsers.push({ sw_id: swId, userData: [[rand(corps), rand(depts), '사원', rand(users), '2024.01~12', '신청완료']] });
|
||||
}
|
||||
|
||||
// 7. 영구 SW 20개
|
||||
for (let i = 1; i <= 20; i++) {
|
||||
const swId = Math.random().toString(36).substring(2, 9);
|
||||
permSw.push({
|
||||
id: swId,
|
||||
type: '영구SW',
|
||||
분야: rand(['설계S/W']),
|
||||
법인: rand(corps),
|
||||
제품명: rand(['AutoCAD', '한컴오피스']),
|
||||
구매일: '2023-01-01',
|
||||
라이선스키: `KEY-${swId}`,
|
||||
금액: '500,000',
|
||||
수량: 2,
|
||||
계정명: `license${i}`,
|
||||
구매업체: '총판',
|
||||
비고: ''
|
||||
});
|
||||
}
|
||||
|
||||
return { pc, server, storage, equip, mobile, subSw, permSw, cloud: [], swUsers, logs, sw: [], hw: [] };
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { HardwareAsset, SoftwareAsset, SWUser, HardwareLog } from './excelHandler';
|
||||
import { API_BASE_URL } from './utils';
|
||||
|
||||
// --- State Definitions ---
|
||||
export interface MasterAssetData {
|
||||
@@ -79,8 +80,7 @@ export async function loadMasterDataFromDB() {
|
||||
{ key: 'logs', url: '/api/asset/history' }
|
||||
];
|
||||
|
||||
const host = `http://${location.hostname}:3000`;
|
||||
const results = await Promise.all(endpoints.map(e => fetch(host + e.url)));
|
||||
const results = await Promise.all(endpoints.map(e => fetch(API_BASE_URL + e.url)));
|
||||
|
||||
for (let i = 0; i < endpoints.length; i++) {
|
||||
if (results[i].ok) {
|
||||
@@ -148,7 +148,7 @@ export async function saveAsset(category: string, asset: any) {
|
||||
'vip': '/api/vip/batch'
|
||||
};
|
||||
|
||||
const url = `http://${location.hostname}:3000${endpointMap[category]}`;
|
||||
const url = `${API_BASE_URL}${endpointMap[category]}`;
|
||||
const currentList = [...(state.masterData as any)[category]];
|
||||
const idx = currentList.findIndex(a => a.id === asset.id);
|
||||
|
||||
@@ -194,7 +194,7 @@ export async function deleteAsset(category: string, assetId: string) {
|
||||
'vip': '/api/vip/batch'
|
||||
};
|
||||
|
||||
const url = `http://${location.hostname}:3000${endpointMap[category]}`;
|
||||
const url = `${API_BASE_URL}${endpointMap[category]}`;
|
||||
const currentList = [...(state.masterData as any)[category]];
|
||||
const filteredList = currentList.filter(a => a.id !== assetId);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { PAGE_DESCRIPTIONS } from './schema';
|
||||
|
||||
export const API_BASE_URL = `http://${location.hostname}:3000`;
|
||||
|
||||
/**
|
||||
* ITAM 공통 유틸리티 함수
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user