add /server/status endpoint

This commit is contained in:
Devin Zuczek
2026-08-05 18:42:19 -04:00
parent cc43d57172
commit f185ef97df
8 changed files with 100 additions and 5 deletions
+22 -1
View File
@@ -1,7 +1,8 @@
import { Hono } from 'hono'
import { useWorkersLogger } from 'workers-tagged-logger'
import { logger, withOnError } from '@repo/hono-helpers'
import { countOnlinePlayers } from '@repo/domain/src/presence-db'
import { logger, withDefaultCors, withOnError } from '@repo/hono-helpers'
import { authUnreachable } from './auth-messages'
import { docsPage, fetchSpec } from './docs'
@@ -70,6 +71,26 @@ const app = new Hono<App>()
})
})
// ---- Server status ------------------------------------------------------
// A public, unauthenticated snapshot of the server — what a status page, a Discord
// bot or the homepage can poll without a token. CORS is open on this one route (the
// rest of www is same-origin) so a page hosted anywhere can read it.
//
// `status` is a stub: this handler only runs when the worker is up, so there is no
// state in which it answers anything but "online". It's here so callers can key off
// a field rather than off HTTP 200, and so a real health signal can replace the
// constant without changing the payload's shape.
.get('/server-status', withDefaultCors(), async (c) => {
return c.json({
status: 'online',
// One presence row per account, expired rows excluded — see countOnlinePlayers.
// Players sitting in the lobby count as online, same as anywhere else we read
// presence.
players: await countOnlinePlayers(c.env.DB),
})
})
// ---- Signup -------------------------------------------------------------
// Create an account from the website, behind a Turnstile bot check. The check is what