/**
 * GET /api/zabbix/public-ip
 * Returns the server's current public IP address.
 */

import { NextResponse } from 'next/server';

export async function GET() {
  try {
    const res = await fetch('https://ipinfo.io/json', {
      headers: { Accept: 'application/json' },
      cache: 'no-store',
      signal: AbortSignal.timeout(5000),
    });
    if (!res.ok) throw new Error(`ipinfo ${res.status}`);
    const data = await res.json();
    return NextResponse.json({ ip: data.ip ?? null });
  } catch {
    return NextResponse.json({ ip: null });
  }
}
