Files
Admin_dash/app/api/status/route.ts

54 lines
1.7 KiB
TypeScript
Raw Normal View History

2026-02-08 02:32:45 -05:00
import { NextResponse } from 'next/server';
// Configuration - Update these URLs to match your actual services
const SERVICES = [
{ name: 'Website', url: 'https://www.akkolli.net' },
{ name: 'Gitea', url: 'https://code.akkolli.net' },
{ name: 'Nextcloud', url: 'http://localhost:6060' },
];
export const dynamic = 'force-dynamic';
export async function GET() {
const results = await Promise.all(
SERVICES.map(async (service) => {
const start = performance.now();
try {
// Set a short timeout (e.g., 5 seconds)
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
const response = await fetch(service.url, {
method: 'HEAD',
signal: controller.signal,
cache: 'no-store',
});
clearTimeout(timeoutId);
const end = performance.now();
const latency = Math.round(end - start);
return {
name: service.name,
url: service.url,
status: response.ok ? 'up' : 'down',
latency: latency,
timestamp: new Date().toISOString(),
};
} catch (error) {
return {
name: service.name,
url: service.url,
status: 'down',
latency: 0,
timestamp: new Date().toISOString(),
error: 'Unreachable'
};
}
})
);
return NextResponse.json(results);
}