import Head from 'flareact/head' import MonitorHistogram from '../src/components/monitorHistogram' import { getLastUpdate, getMonitors, getMonitorsHistory, } from '../src/functions/helpers' import config from '../config.yaml' import MonitorStatusLabel from '../src/components/monitorStatusLabel' export async function getEdgeProps() { // get KV data const kvMonitors = await getMonitors() const kvMonitorsFailedDays = await getMonitorsHistory() const kvLastUpdate = await getLastUpdate() // prepare data maps for components let monitorsOperational = true let kvMonitorsMap = {} kvMonitors.forEach(x => { kvMonitorsMap[x.metadata.id] = x.metadata if (x.metadata.operational === false) monitorsOperational = false }) // transform KV list to array of failed days const kvMonitorsFailedDaysArray = kvMonitorsFailedDays.map(x => { return x.name }) return { props: { config, kvMonitorsMap, kvMonitorsFailedDaysArray, monitorsOperational, kvLastUpdate, }, // Revalidate these props once every x seconds revalidate: 5, } } export default function Index({ config, kvMonitorsMap, kvMonitorsFailedDaysArray, monitorsOperational, kvLastUpdate, }) { return (
{config.settings.title}

{config.settings.title}

{monitorsOperational ? config.settings.allmonitorsOperational : config.settings.notAllmonitorsOperational}
{typeof window !== 'undefined' ? (
checked {Math.round((Date.now() - kvLastUpdate) / 1000)} sec ago
) : ( '' )}
{config.monitors.map((monitor, key) => { return (
{monitor.description && ( )}
{monitor.name}
{config.settings.daysInHistogram} days ago
Today
) })}
Powered by{' '} Cloudflare Workers{' '} &{' '} Flareact{' '}
Get Your Status Page
) }