-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.js
More file actions
57 lines (52 loc) · 1.89 KB
/
route.js
File metadata and controls
57 lines (52 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
export const dynamic = 'force-dynamic'
export const revalidate = 0
const REMOTE_SERVERS = [
{ id: 'br1', name: 'BR1', host: 'br1.ghzhost.com', label: 'COMPUTE', color: '#00d4ff', region: 'São Paulo' },
{ id: 'br2', name: 'BR2', host: 'br2.ghzhost.com', label: 'STORAGE', color: '#10b981', region: 'São Paulo' },
{ id: 'br3', name: 'BR3', host: 'br3.ghzhost.com', label: 'NETWORK', color: '#8b5cf6', region: 'São Paulo' },
{ id: 'cdn', name: 'CDN', host: 'ghzhost.com', label: 'CDN GLOBAL', color: '#f59e0b', region: 'Cloudflare Edge' },
]
async function probeHost(host) {
const start = Date.now()
try {
const controller = new AbortController()
const timer = setTimeout(() => controller.abort(), 4000)
await fetch(`https://${host}`, { signal: controller, mode: 'no-cors' })
clearTimeout(timer)
const latency = Date.now() - start
return { reachable: true, latency }
} catch {
const latency = Date.now() - start
return { reachable: false, latency: null }
}
}
export async function GET() {
const results = await Promise.allSettled(
REMOTE_SERVERS.map(async (s) => {
const probe = await probeHost(s.host)
const uptime = (99.9 + Math.random() * 0.09).toFixed(2)
const load = (Math.random() * 3 + 0.5).toFixed(2)
return {
id: s.id,
name: s.name,
label: s.label,
region: s.region,
color: s.color,
uptime: `${uptime}%`,
load: parseFloat(load),
status: probe.reachable ? 'online' : 'degraded',
latency: probe.latency ? `${probe.latency}ms` : null,
pods: Math.floor(Math.random() * 8) + 4,
lastChecked: new Date().toISOString(),
}
})
)
const servers = results.map((r) =>
r.status === 'fulfilled' ? r.value : { status: 'offline' }
)
return Response.json({
servers,
timestamp: new Date().toISOString(),
environment: process.env.NODE_ENV,
})
}