first commit/push
This commit is contained in:
parent
efbdff72c6
commit
cc60991fc0
27 changed files with 11489 additions and 1 deletions
35
src/app/api/ping/route.ts
Normal file
35
src/app/api/ping/route.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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' });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue