Initial commit
This commit is contained in:
53
app/api/status/route.ts
Normal file
53
app/api/status/route.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user