문제: 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 서버사이드용 추가)
20 lines
390 B
TypeScript
20 lines
390 B
TypeScript
import type { NextConfig } from "next";
|
|
|
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL ?? process.env.API_URL ?? 'http://localhost:3005';
|
|
|
|
const nextConfig: NextConfig = {
|
|
compiler: {
|
|
styledComponents: true,
|
|
},
|
|
async rewrites() {
|
|
return [
|
|
{
|
|
source: '/api/:path*',
|
|
destination: `${apiUrl}/api/:path*`,
|
|
},
|
|
];
|
|
},
|
|
};
|
|
|
|
export default nextConfig;
|