feat(web): publish a public status page at /status
Checking whether the service is up required an account, so the answer lived where the people asking could not reach it. The page is rendered on the server with no script at all and refreshes through a meta tag: a status page that needs a working browser is useless at the moment it is read. Two rules follow from it being public. A repository the forge does not list as public keeps its environment visible but loses its name, and the banner always states the worst true thing — a failed deployment forbids the green headline even while the bot answers. WEB_PUBLIC_STATUS=false removes page and route together. /api/status gives the same in JSON, which is what a monitor should watch rather than /api/health — the latter only says the process is alive. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9acb523510
commit
a1e1de7734
11 files changed
+823
No files matched your search
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* Public status page, rendered on the server (M19).
|
||||
*
|
||||
* Same reasoning as the wiki: a page that needs JavaScript to say whether the
|
||||
* service is up is a page that reads as blank to a monitor, a crawler, or
|
||||
* anyone on a connection bad enough to be checking the status in the first
|
||||
* place. There is no script tag here, and the refresh is a meta tag.
|
||||
*/
|
||||
|
||||
const escape = (text) =>
|
||||
String(text ?? '')
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"');
|
||||
|
||||
const REFRESH_SECONDS = 60;
|
||||
|
||||
const STATE_LABELS = {
|
||||
ok: 'Opérationnel',
|
||||
down: 'Hors ligne',
|
||||
busy: 'En cours',
|
||||
unknown: 'Inconnu',
|
||||
};
|
||||
|
||||
const DEPLOY_LABELS = {
|
||||
success: 'Déployé',
|
||||
failed: 'Échec',
|
||||
running: 'En cours',
|
||||
pending: 'En attente',
|
||||
};
|
||||
|
||||
function duration(ms) {
|
||||
const seconds = Math.floor(Number(ms) / 1000);
|
||||
if (!Number.isFinite(seconds) || seconds < 0) return '—';
|
||||
|
||||
const days = Math.floor(seconds / 86_400);
|
||||
const hours = Math.floor((seconds % 86_400) / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
if (days > 0) return `${days} j ${hours} h`;
|
||||
if (hours > 0) return `${hours} h ${minutes} min`;
|
||||
if (minutes > 0) return `${minutes} min`;
|
||||
return `${seconds} s`;
|
||||
}
|
||||
|
||||
function moment(value) {
|
||||
if (!value) return '—';
|
||||
const date = new Date(String(value).includes('T') ? value : `${value}Z`);
|
||||
if (Number.isNaN(date.getTime())) return '—';
|
||||
return date.toLocaleString('fr-FR', { dateStyle: 'medium', timeStyle: 'short' });
|
||||
}
|
||||
|
||||
const pill = (tone, label) => `<span class="status-pill status-pill-${escape(tone)}">${escape(label)}</span>`;
|
||||
|
||||
const tile = (label, value, hint) => `
|
||||
<div class="status-tile">
|
||||
<span class="status-tile-label">${escape(label)}</span>
|
||||
<strong class="status-tile-value">${escape(value)}</strong>
|
||||
${hint ? `<span class="status-tile-hint">${escape(hint)}</span>` : ''}
|
||||
</div>`;
|
||||
|
||||
function environmentRows(environments) {
|
||||
if (environments.length === 0) {
|
||||
return '<p class="status-empty">Aucun déploiement enregistré pour l’instant.</p>';
|
||||
}
|
||||
|
||||
return `<table class="status-table">
|
||||
<thead>
|
||||
<tr><th>Environnement</th><th>Dépôt</th><th>Version</th><th>État</th><th>Le</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${environments
|
||||
.map(
|
||||
(entry) => `<tr>
|
||||
<td><strong>${escape(entry.environment)}</strong></td>
|
||||
<td>${entry.repository ? escape(entry.repository) : '<span class="status-muted">privé</span>'}</td>
|
||||
<td>${entry.releaseTag ? `<code>${escape(entry.releaseTag)}</code>` : '—'}</td>
|
||||
<td>${pill(entry.tone, DEPLOY_LABELS[entry.status] ?? entry.status)}</td>
|
||||
<td class="status-muted">${escape(moment(entry.finishedAt))}</td>
|
||||
</tr>`,
|
||||
)
|
||||
.join('\n ')}
|
||||
</tbody>
|
||||
</table>`;
|
||||
}
|
||||
|
||||
function releaseList(releases) {
|
||||
if (releases.length === 0) {
|
||||
return '<p class="status-empty">Aucune release publiée pour l’instant.</p>';
|
||||
}
|
||||
|
||||
return `<ul class="status-releases">
|
||||
${releases
|
||||
.map((release) => {
|
||||
const label = `${release.repository} · ${release.name}`;
|
||||
const title = release.htmlUrl
|
||||
? `<a href="${escape(release.htmlUrl)}">${escape(label)}</a>`
|
||||
: escape(label);
|
||||
return `<li>
|
||||
<div>${title}${release.prerelease ? ` ${pill('busy', 'préversion')}` : ''}</div>
|
||||
<span class="status-muted">${escape(moment(release.publishedAt))}</span>
|
||||
</li>`;
|
||||
})
|
||||
.join('\n ')}
|
||||
</ul>`;
|
||||
}
|
||||
|
||||
function footer(links) {
|
||||
const entries = [
|
||||
['/wiki', 'Documentation'],
|
||||
['/terms-of-service', 'Conditions d’utilisation'],
|
||||
['/privacy-policy', 'Politique de confidentialité'],
|
||||
links.website && [links.website, 'Site'],
|
||||
links.forge && [links.forge, 'Forge'],
|
||||
links.discordInvite && [links.discordInvite, 'Discord'],
|
||||
].filter(Boolean);
|
||||
|
||||
return `<footer class="status-footer">${entries
|
||||
.map(([href, label]) => `<a href="${escape(href)}">${escape(label)}</a>`)
|
||||
.join(' · ')}</footer>`;
|
||||
}
|
||||
|
||||
/** Turns a snapshot from `status-service.js` into the finished page. */
|
||||
export function renderStatus(snapshot) {
|
||||
const { bot } = snapshot;
|
||||
const failing = snapshot.environments.filter((entry) => entry.status === 'failed');
|
||||
|
||||
// The banner states the worst true thing: a green headline above a failed
|
||||
// deployment is how a status page loses the only thing it has.
|
||||
const headline = !bot.online
|
||||
? { tone: 'down', title: 'Le bot est hors ligne', detail: 'Le service ne répond pas à Discord.' }
|
||||
: failing.length > 0
|
||||
? {
|
||||
tone: 'busy',
|
||||
title: 'Service opérationnel, déploiement en échec',
|
||||
detail: `Le bot répond, mais ${failing.length} environnement(s) n’ont pas reçu leur dernière mise à jour.`,
|
||||
}
|
||||
: { tone: 'ok', title: 'Tous les services fonctionnent', detail: 'Le bot répond à Discord.' };
|
||||
|
||||
return `<!doctype html>
|
||||
<html lang="fr" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="color-scheme" content="dark light" />
|
||||
<meta name="description" content="État en direct des services FWS : bot Discord, déploiements et releases." />
|
||||
<meta name="robots" content="index, follow" />
|
||||
<meta http-equiv="refresh" content="${REFRESH_SECONDS}" />
|
||||
<title>État des services · FWS</title>
|
||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
||||
<link rel="stylesheet" href="/styles.css" />
|
||||
</head>
|
||||
<body class="status-body">
|
||||
<main class="status-page">
|
||||
<header class="status-head">
|
||||
<a class="status-brand" href="/wiki">
|
||||
<img src="/favicon.svg" alt="" width="40" height="40" />
|
||||
<div><strong>FWS</strong><span>État des services</span></div>
|
||||
</a>
|
||||
<span class="status-muted">Actualisé automatiquement toutes les ${REFRESH_SECONDS} secondes</span>
|
||||
</header>
|
||||
|
||||
<section class="status-banner status-banner-${escape(headline.tone)}">
|
||||
<h1>${escape(headline.title)}</h1>
|
||||
<p>${escape(headline.detail)}</p>
|
||||
</section>
|
||||
|
||||
<section class="status-section">
|
||||
<h2>Bot Discord</h2>
|
||||
<div class="status-tiles">
|
||||
${tile('État', STATE_LABELS[bot.state] ?? bot.state)}
|
||||
${tile('En ligne depuis', duration(bot.uptimeMs), `Démarré le ${moment(bot.startedAt)}`)}
|
||||
${tile('Latence Discord', bot.pingMs === null ? '—' : `${bot.pingMs} ms`)}
|
||||
${tile('Version', bot.version)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="status-section">
|
||||
<h2>Déploiements</h2>
|
||||
${environmentRows(snapshot.environments)}
|
||||
</section>
|
||||
|
||||
<section class="status-section">
|
||||
<h2>Dernières releases</h2>
|
||||
${releaseList(snapshot.releases)}
|
||||
</section>
|
||||
|
||||
<p class="status-muted status-generated">
|
||||
Relevé du <time datetime="${escape(snapshot.generatedAt)}">${escape(moment(snapshot.generatedAt))}</time>.
|
||||
Version lisible par une machine : <a href="/api/status">/api/status</a>.
|
||||
</p>
|
||||
${footer(snapshot.links)}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
Reference in new issue
Block a user