mirror of
https://github.com/ktds-dg0501/kt-event-marketing-fe.git
synced 2025-12-06 09:36:23 +00:00
API 타임아웃을 3분으로 증가
- Next.js API Route fetch 타임아웃: 60초 → 180초 - Nginx 프록시 타임아웃: 60초 → 180초 - 이미지 생성 API의 504 Gateway Timeout 해결 - AbortController를 사용한 타임아웃 제어 추가
This commit is contained in:
parent
950d0284d9
commit
4b52623f07
@ -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
|
||||||
|
|||||||
@ -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(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user