This commit is contained in:
eric
2026-03-16 09:32:35 -05:00
parent c54c236d1b
commit 14b0cd2429
21 changed files with 1058 additions and 706 deletions

View File

@@ -28,7 +28,7 @@ function getApiCandidates(request: NextRequest): string[] {
return urls.filter((u, i) => u && urls.indexOf(u) === i);
}
const TIMEOUT_MS = 20000;
const TIMEOUT_MS = 15000;
export async function postSalonApi(
request: NextRequest,
@@ -67,16 +67,18 @@ export async function postSalonApi(
export async function getSalonApi(
request: NextRequest,
path: string
path: string,
options?: { timeoutMs?: number }
): Promise<{ status: number; data: unknown }> {
const candidates = getApiCandidates(request);
if (!candidates.length) throw new Error("PAYMENT_API_URL 未配置");
const timeoutMs = options?.timeoutMs ?? TIMEOUT_MS;
let lastError: unknown = null;
for (const apiUrl of candidates) {
const url = `${apiUrl}${path}`;
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
try {
const res = await fetch(url, { cache: "no-store", signal: controller.signal });
clearTimeout(timeoutId);