동적 URL 감지 함수를 추가

This commit is contained in:
dohyeons
2025-10-24 09:37:12 +09:00
parent 6fe49721db
commit 5f4d78640b

View File

@@ -3,7 +3,27 @@
*/
import { DashboardElement } from "@/components/admin/dashboard/types";
import { API_BASE_URL } from "./client";
// API URL 동적 설정
function getApiBaseUrl(): string {
// 클라이언트 사이드에서만 실행
if (typeof window !== "undefined") {
const hostname = window.location.hostname;
// 프로덕션: v1.vexplor.com → https://api.vexplor.com/api
if (hostname === "v1.vexplor.com") {
return "https://api.vexplor.com/api";
}
// 로컬 개발: localhost → http://localhost:8080/api
if (hostname === "localhost" || hostname === "127.0.0.1") {
return "http://localhost:8080/api";
}
}
// 서버 사이드 렌더링 시 기본값
return "/api";
}
// 토큰 가져오기 (실제 인증 시스템에 맞게 수정)
function getAuthToken(): string | null {
@@ -17,6 +37,7 @@ async function apiRequest<T>(
options: RequestInit = {},
): Promise<{ success: boolean; data?: T; message?: string; pagination?: any }> {
const token = getAuthToken();
const API_BASE_URL = getApiBaseUrl();
const config: RequestInit = {
headers: {