portfolio api 오류 수정
This commit is contained in:
24
src/api.js
24
src/api.js
@@ -1,25 +1,7 @@
|
|||||||
// src/api.js
|
// src/api.js
|
||||||
const API_BASE = import.meta.env.VITE_API_BASE || "";
|
// 프론트와 API가 동일 도메인(nginx 프록시)이므로 항상 상대 경로 사용.
|
||||||
|
// 절대 URL(VITE_API_BASE)은 Mixed Content를 유발하므로 사용하지 않음.
|
||||||
const toApiUrl = (path) => {
|
const toApiUrl = (path) => path;
|
||||||
if (!API_BASE) return path;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const base = new URL(API_BASE, window.location.origin);
|
|
||||||
// Ensure base pathname ends with '/' if it's not the root or if likely intended as a directory
|
|
||||||
if (!base.pathname.endsWith('/')) {
|
|
||||||
base.pathname += '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove leading slash from path to avoid double slashes when joining
|
|
||||||
const cleanPath = path.startsWith('/') ? path.slice(1) : path;
|
|
||||||
|
|
||||||
return new URL(cleanPath, base).toString();
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Invalid VITE_API_BASE configuration:", error);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function apiGet(path) {
|
export async function apiGet(path) {
|
||||||
const res = await fetch(toApiUrl(path), {
|
const res = await fetch(toApiUrl(path), {
|
||||||
|
|||||||
Reference in New Issue
Block a user