51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
|
|
const BE_BASE_URL = process.env.BE_BASE_URL || "http://localhost:5000";
|
|
const COOKIE_NAME = "auth_token";
|
|
|
|
export async function GET(request: Request) {
|
|
try {
|
|
const { cookies } = await import("next/headers");
|
|
const cookieStore = await cookies();
|
|
const token = cookieStore.get(COOKIE_NAME)?.value;
|
|
|
|
if (!token) {
|
|
return NextResponse.json(
|
|
{ message: "Missing Authorization header" },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
// Preserve query string when proxying
|
|
const url = new URL(request.url);
|
|
const queryString = url.search ? url.search : "";
|
|
|
|
console.log(
|
|
"[DEBUG] - URL",
|
|
`${BE_BASE_URL}/api/v1/users/list${queryString}`
|
|
);
|
|
|
|
const response = await fetch(
|
|
`${BE_BASE_URL}/api/v1/users/list${queryString}`,
|
|
{
|
|
method: "GET",
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
cache: "no-store",
|
|
}
|
|
);
|
|
|
|
console.log("[DEBUG] - Response", response);
|
|
const data = await response.json();
|
|
return NextResponse.json(data, { status: response.status });
|
|
} catch (err: unknown) {
|
|
console.error("Proxy GET /api/v1/users/list error:", err);
|
|
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
return NextResponse.json(
|
|
{ message: "Internal server error", error: errorMessage },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|