31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
|
|
export async function POST(req: Request) {
|
|
try {
|
|
const body = await req.json();
|
|
const headers = req.headers;
|
|
|
|
// Get IP here since we are the public facing entity
|
|
const ip = headers.get('x-forwarded-for') || 'unknown';
|
|
|
|
// Relay to Admin Dashboard (Internal Docker Network)
|
|
// admin_dash must be reachable. If in same docker network, use container name.
|
|
// If separate, use host.docker.internal or configured URL.
|
|
const adminUrl = process.env.ADMIN_DASH_URL || 'http://admin_dash:3000/api/track';
|
|
|
|
// We fire and forget - don't wait for response to keep this fast
|
|
fetch(adminUrl, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ ...body, ip }), // Pass IP along
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-Forwarded-For': ip // Preserve IP
|
|
},
|
|
}).catch(e => console.error('Relay failed', e));
|
|
|
|
return NextResponse.json({ success: true });
|
|
} catch (error) {
|
|
return NextResponse.json({ success: false });
|
|
}
|
|
}
|