2020-11-08 13:56:02 +01:00
|
|
|
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()
|
2020-11-11 23:39:54 +01:00
|
|
|
const kvMonitorsFailedDays = await getMonitorsHistory()
|
2020-11-08 13:56:02 +01:00
|
|
|
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
|
|
|
|
})
|
|
|
|
|
2020-11-11 23:39:54 +01:00
|
|
|
// transform KV list to array of failed days
|
|
|
|
const kvMonitorsFailedDaysArray = kvMonitorsFailedDays.map(x => {
|
|
|
|
return x.name
|
2020-11-08 13:56:02 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
config,
|
|
|
|
kvMonitorsMap,
|
2020-11-11 23:39:54 +01:00
|
|
|
kvMonitorsFailedDaysArray,
|
2020-11-08 13:56:02 +01:00
|
|
|
monitorsOperational,
|
|
|
|
kvLastUpdate,
|
|
|
|
},
|
|
|
|
// Revalidate these props once every x seconds
|
|
|
|
revalidate: 5,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Index({
|
|
|
|
config,
|
|
|
|
kvMonitorsMap,
|
2020-11-11 23:39:54 +01:00
|
|
|
kvMonitorsFailedDaysArray,
|
2020-11-08 13:56:02 +01:00
|
|
|
monitorsOperational,
|
|
|
|
kvLastUpdate,
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Head>
|
|
|
|
<title>{config.settings.title}</title>
|
|
|
|
<link
|
|
|
|
rel="stylesheet"
|
|
|
|
href="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/semantic.min.css"
|
|
|
|
crossOrigin="anonymous"
|
|
|
|
/>
|
|
|
|
<link rel="stylesheet" href="./main.css" />
|
|
|
|
</Head>
|
|
|
|
<div className="ui basic segment container">
|
|
|
|
<h1 className="ui huge header">
|
|
|
|
<img
|
|
|
|
className="ui middle aligned tiny image"
|
|
|
|
src={config.settings.logo}
|
|
|
|
/>
|
|
|
|
{config.settings.title}
|
|
|
|
</h1>
|
|
|
|
<div
|
|
|
|
className={`ui inverted segment ${
|
|
|
|
monitorsOperational ? 'green' : 'yellow'
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<div className="horizontal flex between">
|
|
|
|
<div className="ui marginless header black-text">
|
|
|
|
{monitorsOperational
|
|
|
|
? config.settings.allmonitorsOperational
|
|
|
|
: config.settings.notAllmonitorsOperational}
|
|
|
|
</div>
|
2020-11-12 18:57:42 +01:00
|
|
|
{typeof window !== 'undefined' ? (
|
|
|
|
<div className="black-text">
|
|
|
|
checked {Math.round((Date.now() - kvLastUpdate) / 1000)} sec ago
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)}
|
2020-11-08 13:56:02 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{config.monitors.map((monitor, key) => {
|
|
|
|
return (
|
|
|
|
<div key={key} className="ui segment">
|
|
|
|
<div
|
|
|
|
className="ui horizontal flex between"
|
|
|
|
style={{ marginBottom: '8px' }}
|
|
|
|
>
|
|
|
|
<div className="ui marginless header">
|
2020-11-14 15:05:20 +01:00
|
|
|
{monitor.description && (
|
|
|
|
<span data-tooltip={monitor.description}>
|
|
|
|
<i className="blue small info circle icon" />
|
|
|
|
</span>
|
|
|
|
)}
|
2020-11-08 13:56:02 +01:00
|
|
|
<div className="content">{monitor.name}</div>
|
|
|
|
</div>
|
|
|
|
<MonitorStatusLabel
|
|
|
|
kvMonitorsMap={kvMonitorsMap}
|
|
|
|
monitor={monitor}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<MonitorHistogram
|
2020-11-11 23:39:54 +01:00
|
|
|
kvMonitorsFailedDaysArray={kvMonitorsFailedDaysArray}
|
2020-11-08 13:56:02 +01:00
|
|
|
monitor={monitor}
|
2020-11-11 23:39:54 +01:00
|
|
|
kvMonitor={kvMonitorsMap[monitor.id]}
|
2020-11-08 13:56:02 +01:00
|
|
|
/>
|
|
|
|
|
|
|
|
<div className="horizontal flex between grey-text">
|
2020-11-11 23:39:54 +01:00
|
|
|
<div>{config.settings.daysInHistogram} days ago</div>
|
2020-11-08 13:56:02 +01:00
|
|
|
<div>Today</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
<div className="horizontal flex between grey-text">
|
|
|
|
<div>
|
|
|
|
Powered by{' '}
|
|
|
|
<a href="https://workers.cloudflare.com/" target="_blank">
|
|
|
|
Cloudflare Workers{' '}
|
|
|
|
</a>
|
|
|
|
&{' '}
|
|
|
|
<a href="https://flareact.com/" target="_blank">
|
|
|
|
Flareact{' '}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<a
|
2020-11-14 02:57:06 +01:00
|
|
|
href="https://github.com/eidam/cf-workers-status-page"
|
2020-11-08 13:56:02 +01:00
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
Get Your Status Page
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|