Use Vite API base URL for web deploys

This commit is contained in:
dahyeon committed 2026-07-03 05:09:59 -07:00
1 parent f80834c6ab
commit ffcba26e64
5 files changed
+14 -2

No files matched your search

+1
View File
@@ -0,0 +1 @@
VITE_API_BASE_URL=https://persona-lenz-api.dahyeon.us
+1
View File
@@ -0,0 +1 @@
VITE_API_BASE_URL=https://persona-lenz-api-staging.dahyeon.us
+9
View File
@@ -0,0 +1,9 @@
export const API_BASE_URL = (
import.meta.env.VITE_API_BASE_URL ?? ''
).replace(/\/$/, '')
export function resolveApiUrl(path: string): string {
if (/^https?:\/\//i.test(path)) return path
const normalizedPath = path.startsWith('/') ? path : `/${path}`
return API_BASE_URL ? `${API_BASE_URL}${normalizedPath}` : normalizedPath
}
+2 -1
View File
@@ -5,6 +5,7 @@ import type {
PlayerAnalysisDto, PlayerAnalysisDto,
SimilarPlayersDto, SimilarPlayersDto,
} from '@persona-lenz/shared' } from '@persona-lenz/shared'
import { resolveApiUrl } from '../config'
export class ApiError extends Error { export class ApiError extends Error {
readonly status: number readonly status: number
@@ -19,7 +20,7 @@ export class ApiError extends Error {
async function request<T>(path: string, init?: RequestInit): Promise<T> { async function request<T>(path: string, init?: RequestInit): Promise<T> {
let response: Response let response: Response
try { try {
response = await fetch(path, init) response = await fetch(resolveApiUrl(path), init)
} catch { } catch {
throw new ApiError(0, '서버에 연결하지 못했어요. 네트워크를 확인하고 다시 시도해 주세요.') throw new ApiError(0, '서버에 연결하지 못했어요. 네트워크를 확인하고 다시 시도해 주세요.')
} }
+1 -1
View File
@@ -237,7 +237,7 @@ function validateEnv(mode, env) {
function resolveRequiredEnvKeys(env) { function resolveRequiredEnvKeys(env) {
const rawKeys = env.CF_PAGES_REQUIRED_ENV_KEYS?.trim(); const rawKeys = env.CF_PAGES_REQUIRED_ENV_KEYS?.trim();
if (!rawKeys) return []; if (!rawKeys) return ["VITE_API_BASE_URL"];
return rawKeys return rawKeys
.split(",") .split(",")
.map((key) => key.trim()) .map((key) => key.trim())