43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
||
import { postMeetupApi } from "../_paymentApi";
|
||
|
||
/** Vercel serverless 超时时间(秒),避免上游慢导致 502 */
|
||
export const maxDuration = 20;
|
||
|
||
export async function POST(request: NextRequest) {
|
||
try {
|
||
const body = await request.json().catch(() => ({}));
|
||
const email = String(body?.email || "").trim();
|
||
if (!email) {
|
||
return NextResponse.json({ ok: false, error: "Please enter your email" }, { status: 400 });
|
||
}
|
||
|
||
const { status, data } = await postMeetupApi(request, "/api/meetup/check-user", { email });
|
||
|
||
// 上游返回 5xx 时,统一为 503 并返回友好提示,避免直接透传 502
|
||
if (status >= 500) {
|
||
const payload = typeof data === "object" && data !== null ? (data as Record<string, unknown>) : {};
|
||
return NextResponse.json(
|
||
{ ok: false, error: (payload.error as string) || "服务暂时不可用,请稍后重试" },
|
||
{ status: 503 }
|
||
);
|
||
}
|
||
|
||
return NextResponse.json(data, { status });
|
||
} catch (error) {
|
||
const isTimeout =
|
||
error instanceof Error &&
|
||
(error.name === "AbortError" || error.message.toLowerCase().includes("abort"));
|
||
console.error("check-user error:", error);
|
||
return NextResponse.json(
|
||
{
|
||
ok: false,
|
||
error: isTimeout
|
||
? "请求超时,请确认 payjsapi 已启动(cd payjsapi && python run.py)"
|
||
: "服务暂时不可用,请稍后重试",
|
||
},
|
||
{ status: 503 }
|
||
);
|
||
}
|
||
}
|