fix: API URL 하드코딩 문제 해결 및 API 통합 개선
- API URL 생성 로직에서 localhost 환경 감지 개선 - 모든 페이지에서 하드코딩된 API URL 제거 - ManagementAPI, InboxAPI 추가로 API 호출 통합 - ProjectsAPI 사용으로 프로젝트 로드 통일 - permissions.js에서 API URL 동적 생성 적용
This commit is contained in:
@@ -339,30 +339,20 @@
|
||||
async function loadProjects() {
|
||||
try {
|
||||
// API에서 최신 프로젝트 데이터 가져오기
|
||||
const apiUrl = window.API_BASE_URL || 'http://localhost:16080/api';
|
||||
const response = await fetch(`${apiUrl}/projects/`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('access_token')}`,
|
||||
'Content-Type': 'application/json'
|
||||
const apiUrl = window.API_BASE_URL || (() => {
|
||||
const hostname = window.location.hostname;
|
||||
if (hostname === 'm.hyungi.net') {
|
||||
return 'https://m-api.hyungi.net/api';
|
||||
}
|
||||
});
|
||||
return '/api';
|
||||
})();
|
||||
// ProjectsAPI 사용 (모든 프로젝트 로드)
|
||||
projects = await ProjectsAPI.getAll(false);
|
||||
console.log('프로젝트 로드 완료:', projects.length, '개');
|
||||
console.log('활성 프로젝트:', projects.filter(p => p.is_active).length, '개');
|
||||
|
||||
if (response.ok) {
|
||||
projects = await response.json();
|
||||
console.log('프로젝트 로드 완료:', projects.length, '개');
|
||||
console.log('활성 프로젝트:', projects.filter(p => p.is_active).length, '개');
|
||||
|
||||
// localStorage에도 캐시 저장
|
||||
localStorage.setItem('work-report-projects', JSON.stringify(projects));
|
||||
} else {
|
||||
console.error('프로젝트 로드 실패:', response.status);
|
||||
// 실패 시 localStorage에서 로드
|
||||
const saved = localStorage.getItem('work-report-projects');
|
||||
if (saved) {
|
||||
projects = JSON.parse(saved);
|
||||
console.log('캐시에서 프로젝트 로드:', projects.length, '개');
|
||||
}
|
||||
}
|
||||
// localStorage에도 캐시 저장
|
||||
localStorage.setItem('work-report-projects', JSON.stringify(projects));
|
||||
} catch (error) {
|
||||
console.error('프로젝트 로드 오류:', error);
|
||||
// 오류 시 localStorage에서 로드
|
||||
|
||||
Reference in New Issue
Block a user