(plan) convert original implement plan to mock api

This commit is contained in:
Story Crater Bot
2026-08-19 09:47:14 -07:00
parent c42040319f
commit 0aef2281bc
65 changed files with 307 additions and 627 deletions
+42
View File
@@ -0,0 +1,42 @@
import { cluster, namespaces } from '@/lib/clusterMock'
/**
* Mock stand-in for the real atlas `GET /api/stream`. Emits synthetic `topology` deltas on an
* interval and a keepalive comment frame, matching the SSE shape the frontend expects — no real
* informer, no real cluster.
*/
export async function GET(req: Request) {
const encoder = new TextEncoder()
let seq = cluster.generation
const stream = new ReadableStream({
start(controller) {
const send = (event: string, data: unknown) => {
controller.enqueue(encoder.encode(`event: ${event}\nid: ${seq++}\ndata: ${JSON.stringify(data)}\n\n`))
}
const keepalive = setInterval(() => {
controller.enqueue(encoder.encode(': keepalive\n\n'))
}, 30_000)
const delta = setInterval(() => {
const ns = namespaces[Math.floor(Math.random() * namespaces.length)]
send('topology', { namespace: ns.name, running: ns.running, total: ns.total })
}, 5_000)
req.signal.addEventListener('abort', () => {
clearInterval(keepalive)
clearInterval(delta)
controller.close()
})
},
})
return new Response(stream, {
headers: {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
Connection: 'keep-alive',
},
})
}