43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import {
|
|
applyAuthResponseCookies,
|
|
buildBackendRequestHeaders,
|
|
requireBackendPaymentAuth,
|
|
} from "@/lib/backend-auth";
|
|
import { buildProxyExceptionResponse } from "@/lib/api-proxy";
|
|
|
|
const API_BASE = process.env.POLYWEATHER_API_BASE_URL;
|
|
|
|
export async function POST(req: NextRequest) {
|
|
if (!API_BASE) {
|
|
return NextResponse.json(
|
|
{ error: "POLYWEATHER_API_BASE_URL is not configured" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
|
|
try {
|
|
const auth = await buildBackendRequestHeaders(req);
|
|
const authError = requireBackendPaymentAuth(auth);
|
|
if (authError) return authError;
|
|
const res = await fetch(`${API_BASE}/api/payments/reconcile-latest`, {
|
|
method: "POST",
|
|
headers: auth.headers,
|
|
cache: "no-store",
|
|
});
|
|
const raw = await res.text();
|
|
const response = new NextResponse(raw, {
|
|
status: res.status,
|
|
headers: {
|
|
"content-type":
|
|
res.headers.get("content-type") || "application/json; charset=utf-8",
|
|
},
|
|
});
|
|
return applyAuthResponseCookies(response, auth.response);
|
|
} catch (error) {
|
|
return buildProxyExceptionResponse(error, {
|
|
publicMessage: "Failed to reconcile latest payment",
|
|
});
|
|
}
|
|
}
|