43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import axios from 'axios';
|
|
|
|
// 개발: Vite 프록시 → /api (localhost:4000)
|
|
// 배포: VITE_API_URL 미설정 시 Render 백엔드 기본값 사용
|
|
const RENDER_API = 'https://eene-dashboard-backend.onrender.com';
|
|
const baseURL = import.meta.env.VITE_API_URL
|
|
? `${import.meta.env.VITE_API_URL}/api`
|
|
: import.meta.env.PROD
|
|
? `${RENDER_API}/api`
|
|
: '/api';
|
|
|
|
export const apiClient = axios.create({
|
|
baseURL,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
|
|
export function fileViewUrl(fileId: string): string {
|
|
return `${baseURL}/files/${fileId}/view`;
|
|
}
|
|
|
|
export function fileDownloadUrl(fileId: string): string {
|
|
return `${baseURL}/files/${fileId}/download`;
|
|
}
|
|
|
|
apiClient.interceptors.request.use((config) => {
|
|
if (config.data instanceof FormData) {
|
|
delete config.headers['Content-Type'];
|
|
}
|
|
return config;
|
|
});
|
|
|
|
apiClient.interceptors.response.use(
|
|
(res) => res,
|
|
(error) => Promise.reject(error),
|
|
);
|
|
|
|
export function getApiErrorMessage(err: unknown, fallback: string): string {
|
|
const ax = err as { response?: { data?: { message?: string }; status?: number }; message?: string };
|
|
return ax.response?.data?.message || ax.message || fallback;
|
|
}
|