- 일일순회점검 시스템 신규 구현 - DB 테이블: patrol_checklist_items, daily_patrol_sessions, patrol_check_records, workplace_items, item_types - API: /api/patrol/* 엔드포인트 - 프론트엔드: 지도 기반 작업장 점검 UI - 설비 관리 기능 개선 - 구매 관련 필드 추가 (구매일, 가격, 공급업체 등) - 설비 코드 자동 생성 (TKP-XXX 형식) - 작업장 관리 개선 - 레이아웃 이미지 업로드 기능 - 마커 위치 저장 기능 - 부서 관리 기능 추가 - 사이드바 네비게이션 카테고리 재구성 - 이미지 401 오류 수정 (정적 파일 경로 처리) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
// /js/api-base.js
|
|
// API 기본 설정 (비모듈 - 빠른 로딩용)
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
const API_PORT = 20005;
|
|
const API_PATH = '/api';
|
|
|
|
function getApiBaseUrl() {
|
|
const hostname = window.location.hostname;
|
|
const protocol = window.location.protocol;
|
|
return `${protocol}//${hostname}:${API_PORT}${API_PATH}`;
|
|
}
|
|
|
|
// 전역 API 설정
|
|
const apiUrl = getApiBaseUrl();
|
|
window.API_BASE_URL = apiUrl;
|
|
window.API = apiUrl; // 이전 호환성
|
|
|
|
// 인증 헤더 생성
|
|
window.getAuthHeaders = function() {
|
|
const token = localStorage.getItem('token');
|
|
return {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': token ? `Bearer ${token}` : ''
|
|
};
|
|
};
|
|
|
|
// API 호출 헬퍼 (기존 시그니처 유지: endpoint, method, data)
|
|
// JSON 파싱하여 반환
|
|
window.apiCall = async function(endpoint, method = 'GET', data = null) {
|
|
const url = `${window.API_BASE_URL}${endpoint}`;
|
|
const config = {
|
|
method: method,
|
|
headers: window.getAuthHeaders()
|
|
};
|
|
|
|
if (data && (method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE')) {
|
|
config.body = JSON.stringify(data);
|
|
}
|
|
|
|
const response = await fetch(url, config);
|
|
|
|
// 401 Unauthorized 처리
|
|
if (response.status === 401) {
|
|
localStorage.removeItem('token');
|
|
localStorage.removeItem('user');
|
|
window.location.href = '/index.html';
|
|
throw new Error('인증이 만료되었습니다.');
|
|
}
|
|
|
|
// JSON 파싱하여 반환
|
|
return response.json();
|
|
};
|
|
|
|
console.log('✅ API 설정 완료:', window.API_BASE_URL);
|
|
})();
|