fix: 첨부 다운로드 링크를 백엔드 절대 URL 로 변환
백엔드가 내려준 루트 상대경로(/api/.../download)를 <a href> 가 프론트 오리진으로 해석해 404 페이지가 뜨던 문제 수정. useApi 에 toAbsoluteApiUrl 추가, 첨부 매핑에 적용. (dev 프론트 5273 / 백엔드 3100 오리진 분리 환경) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,19 @@ const api: AxiosInstance = axios.create({
|
||||
withCredentials: true,
|
||||
})
|
||||
|
||||
// 백엔드 오리진 — <a href> 다운로드 링크용. axios 와 달리 앵커는 baseURL 을 쓰지 않으므로,
|
||||
// 백엔드가 내려준 루트 상대 경로('/api/...')에 백엔드 오리진을 붙여 절대 URL 로 만든다.
|
||||
// (dev 는 프론트 5273 / 백엔드 3100 로 오리진이 달라, 안 붙이면 프론트로 가서 404 페이지가 뜬다)
|
||||
const API_ORIGIN = new URL(
|
||||
import.meta.env.VITE_API_BASE_URL || '/api',
|
||||
window.location.origin,
|
||||
).origin
|
||||
|
||||
export function toAbsoluteApiUrl(path: string): string {
|
||||
if (!path || /^https?:\/\//i.test(path)) return path
|
||||
return `${API_ORIGIN}${path.startsWith('/') ? '' : '/'}${path}`
|
||||
}
|
||||
|
||||
// 요청 인터셉터 — CSRF, 추가 헤더 등 필요 시 확장
|
||||
api.interceptors.request.use(
|
||||
(config: InternalAxiosRequestConfig) => config,
|
||||
|
||||
Reference in New Issue
Block a user