You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
import { NextRequest, NextResponse } from "next/server";
|
|
import { requireLogin } from "@/app/api/_auth";
|
|
const UPSTREAM_RECOMMEND_BANNER_LIST_PATH =
|
|
"/api_client/anime/recommendBanner/list";
|
|
|
|
function getPopiBaseUrl() {
|
|
return process.env.POPIART_API_BASE_URL?.replace(/\/+$/, "") || "";
|
|
}
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const baseUrl = getPopiBaseUrl();
|
|
if (!baseUrl) {
|
|
return NextResponse.json(
|
|
{ status: "5000", message: "POPIART_API_BASE_URL is not configured" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
const { token } = requireLogin(request);
|
|
console.log("token", token);
|
|
const upstreamUrl = new URL(UPSTREAM_RECOMMEND_BANNER_LIST_PATH, baseUrl);
|
|
upstreamUrl.searchParams.set(
|
|
"origin",
|
|
request.nextUrl.searchParams.get("origin") || "",
|
|
);
|
|
|
|
const response = await fetch(upstreamUrl, {
|
|
method: "GET",
|
|
headers: {
|
|
authorization: `Bearer ${token}`,
|
|
},
|
|
});
|
|
const body = await response.text();
|
|
console.log("Upstream response body:", body);
|
|
return new NextResponse(body, {
|
|
status: response.status,
|
|
headers: {
|
|
"Content-Type":
|
|
response.headers.get("Content-Type") || "application/json",
|
|
},
|
|
});
|
|
}
|
|
|