API 타임아웃을 3분으로 증가

- Next.js API Route fetch 타임아웃: 60초 → 180초
- Nginx 프록시 타임아웃: 60초 → 180초
- 이미지 생성 API의 504 Gateway Timeout 해결
- AbortController를 사용한 타임아웃 제어 추가
This commit is contained in:
cherry2250 2025-10-30 14:46:37 +09:00
parent 950d0284d9
commit 4b52623f07
2 changed files with 32 additions and 14 deletions

View File

@ -55,10 +55,10 @@ http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
# Timeouts # Timeouts - 이미지 생성은 시간이 오래 걸리므로 3분으로 설정
proxy_connect_timeout 60s; proxy_connect_timeout 180s;
proxy_send_timeout 60s; proxy_send_timeout 180s;
proxy_read_timeout 60s; proxy_read_timeout 180s;
} }
# Static files # Static files

View File

@ -11,13 +11,20 @@ export async function POST(request: NextRequest) {
body, body,
}); });
// 이미지 생성은 시간이 오래 걸리므로 타임아웃을 3분으로 설정
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 180000); // 3분
try {
const response = await fetch(`${CONTENT_API_BASE_URL}/api/v1/content/images/generate`, { const response = await fetch(`${CONTENT_API_BASE_URL}/api/v1/content/images/generate`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify(body), body: JSON.stringify(body),
signal: controller.signal,
}); });
clearTimeout(timeoutId);
if (!response.ok) { if (!response.ok) {
const errorText = await response.text(); const errorText = await response.text();
@ -32,6 +39,17 @@ export async function POST(request: NextRequest) {
console.log('✅ Image generation job created:', data); console.log('✅ Image generation job created:', data);
return NextResponse.json(data); return NextResponse.json(data);
} catch (fetchError) {
clearTimeout(timeoutId);
if (fetchError instanceof Error && fetchError.name === 'AbortError') {
console.error('❌ Request timeout after 3 minutes');
return NextResponse.json(
{ error: 'Request timeout', details: 'Image generation request timed out after 3 minutes' },
{ status: 504 }
);
}
throw fetchError;
}
} catch (error) { } catch (error) {
console.error('❌ Proxy error:', error); console.error('❌ Proxy error:', error);
return NextResponse.json( return NextResponse.json(