fix: 서버 전용 키가 브라우저 번들에 들어가지 않게 한다
- vite.config define 의 GEMINI_API_KEY 를 지운다 - API 대시보드의 import.meta.env 동적 조회를 공개 변수 목록으로 바꾼다. 동적 조회 때문에 VITE_ 변수 전체(VITE_CREATOMATE_API_KEY 포함)가 번들에 들어갔다 - 모든 배포 빌드 끝에 서버 전용 키 값이 번들에 있으면 빌드를 실패시킨다 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0b729759c3
commit
e20a90dc35
3 files changed
+50
-12
No files matched your search
@@ -147,7 +147,7 @@ const API_REGISTRY: ApiConfig[] = [
|
||||
name: 'Google Gemini',
|
||||
description: 'AI 이미지 생성 + Vision 분석 (스크린샷 OCR)',
|
||||
envKeys: ['GEMINI_API_KEY'],
|
||||
layer: 'both',
|
||||
layer: 'edge-function',
|
||||
docsUrl: 'https://ai.google.dev/docs',
|
||||
IconComponent: DatabaseFilled,
|
||||
category: 'ai',
|
||||
@@ -161,8 +161,8 @@ const API_REGISTRY: ApiConfig[] = [
|
||||
id: 'creatomate',
|
||||
name: 'Creatomate',
|
||||
description: '마케팅 영상 자동 생성 (템플릿 기반)',
|
||||
envKeys: ['VITE_CREATOMATE_API_KEY'],
|
||||
layer: 'frontend',
|
||||
envKeys: ['CREATOMATE_API_KEY'],
|
||||
layer: 'edge-function',
|
||||
docsUrl: 'https://creatomate.com/docs/api/introduction',
|
||||
IconComponent: VideoFilled,
|
||||
category: 'ai',
|
||||
@@ -176,12 +176,19 @@ const API_REGISTRY: ApiConfig[] = [
|
||||
|
||||
/* ────────────────── Environment Variable Checker ─────────────── */
|
||||
|
||||
// 브라우저에서 확인할 수 있는 값은 공개를 전제로 만든 변수뿐이다. import.meta.env 를 이름으로 동적 조회하면
|
||||
// Vite 가 VITE_ 변수 전체를 번들에 넣으므로(2026-10-07 VITE_CREATOMATE_API_KEY 노출 원인), 여기 적은 것만 읽는다.
|
||||
const PUBLIC_ENV: Record<string, string | undefined> = {
|
||||
VITE_SUPABASE_URL: import.meta.env.VITE_SUPABASE_URL,
|
||||
VITE_SUPABASE_ANON_KEY: import.meta.env.VITE_SUPABASE_ANON_KEY,
|
||||
};
|
||||
|
||||
function checkEnvVars(): ApiStatusInfo[] {
|
||||
return API_REGISTRY.map((api) => {
|
||||
const keyPresent: Record<string, boolean> = {};
|
||||
for (const key of api.envKeys) {
|
||||
if (key.startsWith('VITE_')) {
|
||||
const val = (import.meta.env as Record<string, string | undefined>)[key];
|
||||
const val = PUBLIC_ENV[key];
|
||||
keyPresent[key] = !!val && val.length > 0;
|
||||
} else {
|
||||
keyPresent[key] = true;
|
||||
@@ -269,12 +276,12 @@ function EnvKeyRow({ envKey, present, isServerSide }: { key?: string; envKey: st
|
||||
const value = isServerSide
|
||||
? '(Edge Function 환경변수 — 프론트엔드에서 확인 불가)'
|
||||
: showKey
|
||||
? (import.meta.env as Record<string, string | undefined>)[envKey] || ''
|
||||
? PUBLIC_ENV[envKey] || ''
|
||||
: '••••••••••••••••';
|
||||
|
||||
const handleCopy = () => {
|
||||
if (!isServerSide) {
|
||||
navigator.clipboard.writeText((import.meta.env as Record<string, string | undefined>)[envKey] || '');
|
||||
navigator.clipboard.writeText(PUBLIC_ENV[envKey] || '');
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 1500);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user