Spaces:
Sleeping
Sleeping
File size: 958 Bytes
8e0dd55 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import { NextRequest, NextResponse } from "next/server";
const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost:8001';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
// Forward the request to the backend API
const response = await fetch(`${TARGET_SERVER_BASE_URL}/auth/validate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
if (!response.ok) {
return NextResponse.json(
{ error: `Backend server returned ${response.status}` },
{ status: response.status }
);
}
const data = await response.json();
return NextResponse.json(data);
} catch (error) {
console.error('Error forwarding request to backend:', error);
return NextResponse.json(
{ error: 'Internal Server Error' },
{ status: 500 }
);
}
}
|