Open History to see the last commit
1import { createFileRoute } from '@tanstack/react-router'
2import { env } from 'cloudflare:workers'
3
4import { getDb } from '#/db/index.ts'
5import { halGet } from '#/server/hal.ts'
6import { getServiceStatus } from '#/server/status.ts'
7import { parseWaitSeconds, waitForStatusChange } from '#/server/wait.ts'
8
9export const Route = createFileRoute('/v1/status')({
10 server: {
11 handlers: {
12 GET: async ({ request }) => {
13 // ?wait=Ns long-poll (task 11.3): hold until a poll/sync lands.
14 const waitSeconds = parseWaitSeconds(new URL(request.url))
15 if (waitSeconds > 0) {
16 await waitForStatusChange(getDb(env), waitSeconds)
17 }
18 return Response.json({
19 ...(await getServiceStatus(getDb(env))),
20 _links: {
21 self: halGet('/v1/status'),
22 index: halGet('/v1'),
23 providers: halGet('/v1/providers'),
24 },
25 })
26 },
27 },
28 },
29})