30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { getApiUrlFromRequest, getPaymentConfig } from "@/config/services.config";
|
|
|
|
function resolvePayApiUrl(request: NextRequest): string {
|
|
const payConfig = getPaymentConfig();
|
|
const hostHeader = request.headers.get("host") || request.headers.get("x-forwarded-host");
|
|
return (
|
|
(hostHeader ? getApiUrlFromRequest(hostHeader) : null) ||
|
|
payConfig.apiUrl
|
|
).replace(/\/$/, "");
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
const body = await request.json().catch(() => ({}));
|
|
const apiUrl = resolvePayApiUrl(request);
|
|
const res = await fetch(`${apiUrl}/nomadvip/wechat_profile`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body || {}),
|
|
cache: "no-store",
|
|
}).catch(() => null);
|
|
|
|
if (!res) {
|
|
return NextResponse.json({ ok: false, found: false, error: "upstream unavailable" }, { status: 502 });
|
|
}
|
|
const data = await res.json().catch(() => ({}));
|
|
return NextResponse.json(data, { status: res.ok ? 200 : 502 });
|
|
}
|
|
|