fix(hotfix-001): NEXT_PUBLIC_API_URL env 의존 제거 → Next.js rewrites 프록시
문제: FE 빌드 시 NEXT_PUBLIC_API_URL env 없으면 localhost:3005로 하드베이킹됨 → 배포 환경에서 API 요청이 localhost로 가는 버그 해결: - next.config.ts: /api/* → BE(API_URL) rewrites 추가 - lib/config.ts: CSR에서 API_URL='' (상대경로) 사용 SSR에서는 process.env.API_URL ?? NEXT_PUBLIC_API_URL fallback - lib/adminFetch.ts: 상대경로 직접 사용 - 모든 페이지가 use client이므로 CSR 상대경로 + rewrites로 완전 처리 - .env.local.example 업데이트 (API_URL 서버사이드용 추가)
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
import { API_URL } from './config';
|
||||
|
||||
/**
|
||||
* 관리자 API 호출 유틸.
|
||||
* API_URL이 빈 문자열이면 상대경로 → Next.js rewrites → BE 프록시.
|
||||
* Authorization 헤더에 localStorage의 admin key 삽입.
|
||||
*/
|
||||
export function adminFetch(path: string, options?: RequestInit) {
|
||||
const apiKey =
|
||||
typeof window !== 'undefined'
|
||||
? (localStorage.getItem('hanarang_admin_key') ?? '')
|
||||
: '';
|
||||
|
||||
return fetch(`${API_URL}${path}`, {
|
||||
// CSR: path가 /api/... 이면 상대경로 그대로 사용
|
||||
// SSR에서는 adminFetch 미사용 (모든 admin 페이지가 'use client')
|
||||
return fetch(path, {
|
||||
...options,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
Reference in New Issue
Block a user