C.W.K.
Stream
Lesson 05 of 08 · published

Production 의 Environment Variable

~20 min · env, build vs runtime, Docker

Level 0Curious
0 XP0/68 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Build-time vs runtime

변수 종류언제 read?
NEXT_PUBLIC_*Build time — bundle 에 박힘
Server-onlyRuntime — 매 request 에 read

Docker 문제

Image 한 개 build 하고 staging + production 에 다른 setting 으로 deploy? NEXT_PUBLIC_* 값이 환경 사이로 못 변함 — 이미 박혔어. Environment 별 rebuild 하든가 runtime config 전략 (예: proxy 가 inject, 또는 server 에서만 read).

Loading 순서

  1. 이미 set 된 process.env
  2. .env.production.local / .env.development.local
  3. .env.local (test 에선 skip)
  4. .env.production / .env.development
  5. .env

Code

Env var runtime read 강제·tsx
import { connection } from 'next/server';

export default async function Page() {
  await connection(); // per-request render 로 opt-in
  const apiUrl = process.env.API_URL; // 매 request read
  return <div>API: {apiUrl}</div>;
}
Vercel CLI 로 environment scope·bash
vercel env add DATABASE_URL production
vercel env add DATABASE_URL preview
vercel env add DATABASE_URL development

External links

Exercise

NEXT_PUBLIC_* 값 한 set 으로 Docker image build. 두 환경에 deploy 해서 값 매칭 확인 (즉, 박혔다는 거). 한 개를 server-only var 로 refactor 하고 re-deploy.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.