nomadro/app/api/vip/wechat-profile/route.ts
eric 56b29205e7 Integrate four verticals into nomadro portal with shared packages and API gateway.
Mount /vip with nomadvip+payjsapi, add @nomadro/pay|pb|sdk, apps/api, /admin shell, and backup/rollback scripts under git.nomadro.cn workflow.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 20:16:44 -05:00

30 lines
1.0 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { getApiUrlFromRequest, getPaymentConfig } from "@vip/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 });
}