Files
vibepod/web/app/api/health/route.ts
T
google-labs-jules[bot] bd5c667307 chore: refactor duplicated offline response in health api route
Extract the duplicated offline response payload and common headers into
constants to improve maintainability and readability.

- Define OFFLINE_RESPONSE for { status: "offline" }
- Define COMMON_OPTIONS for { headers: { "Cache-Control": "no-store" } }
- Use these constants across all response paths in the route.

Co-authored-by: LyAhn <27559362+LyAhn@users.noreply.github.com>
2026-04-28 14:17:19 +00:00

38 lines
1.1 KiB
TypeScript

import { NextResponse } from "next/server";
const OFFLINE_RESPONSE = { status: "offline" };
const COMMON_OPTIONS = { headers: { "Cache-Control": "no-store" } };
export async function GET() {
const pythonServerUrl =
process.env.VIBEVOICE_SERVER_URL ?? "http://localhost:8000";
try {
const res = await fetch(`${pythonServerUrl}/health`, {
method: "GET",
signal: AbortSignal.timeout(4000),
// Don't cache health checks
cache: "no-store",
});
if (res.ok) {
const data = await res.json().catch(() => ({}));
// Pass through the exact status the Python server reports:
// "online" | "loading" | "error"
const status: string = data.status ?? "online";
return NextResponse.json(
{
status,
message: data.message,
progress: data.progress ?? null,
voices: data.voices ?? [],
},
COMMON_OPTIONS
);
}
return NextResponse.json(OFFLINE_RESPONSE, COMMON_OPTIONS);
} catch {
return NextResponse.json(OFFLINE_RESPONSE, COMMON_OPTIONS);
}
}