import { NextResponse } from 'next/server'; export async function GET(request: Request) { const { searchParams } = new URL(request.url); const url = searchParams.get('url'); if (!url) return NextResponse.json({ status: 'down' }); if (url.startsWith('minecraft://')) { const address = url.replace('minecraft://', ''); try { const res = await fetch(`https://api.mcsrvstat.us/3/${address}`); const data = await res.json(); return NextResponse.json({ status: data.online ? 'up' : 'down' }); } catch { return NextResponse.json({ status: 'down' }); } } try { const httpRes = await fetch(url, { method: 'GET', signal: AbortSignal.timeout(5000) }); // Accept all non-5xx responses as "up". 5xx usually means origin or gateway errors (like Cloudflare 521, 522, etc.) if (httpRes && httpRes.status < 500) { return NextResponse.json({ status: 'up' }); } } catch (e) { console.error(`Failed to ping ${url}`, e); } return NextResponse.json({ status: 'down' }); }