Template
Inital template
This commit is contained in:
commit
54faec3540
62 files changed
+6808
No files matched your search
@@ -0,0 +1 @@
|
||||
export function startMockServer(port?: number): { close(): void }
|
||||
@@ -0,0 +1,67 @@
|
||||
// Zero-dependency mock API used by the Vite dev server via the /api proxy.
|
||||
// Add an endpoint by giving it a key in `routes`; response delay mimics a real network.
|
||||
import { createServer } from 'node:http'
|
||||
|
||||
const stats = [
|
||||
{ label: 'Running apps', value: '12', delta: '+2', up: true, icon: 'apps' },
|
||||
{ label: 'Monthly cost', value: '18 400 kr', delta: '-4%', up: true, icon: 'cost' },
|
||||
{ label: 'Deploys this week', value: '38', delta: '+12%', up: true, icon: 'deploys' },
|
||||
{ label: 'Open findings', value: '3', delta: '+1', up: false, icon: 'findings' },
|
||||
]
|
||||
|
||||
const resources = [
|
||||
{ name: 'case-intake-web', service: 'app', env: 'production', region: 'Borlänge DC', status: 'running' },
|
||||
{ name: 'case-intake-db', service: 'database', env: 'production', region: 'Borlänge DC', status: 'running' },
|
||||
{ name: 'documents', service: 'storage', env: 'production', region: 'Borlänge DC', status: 'running' },
|
||||
{ name: 'classify-case', service: 'function', env: 'staging', region: 'Falun edge', status: 'scaling' },
|
||||
{ name: 'session-cache', service: 'cache', env: 'staging', region: 'Falun edge', status: 'degraded' },
|
||||
]
|
||||
|
||||
const deploys = [
|
||||
{ project: 'case-intake-web', env: 'production', by: 'Circuit agent', time: '2 min ago', ok: true },
|
||||
{ project: 'classify-case', env: 'staging', by: 'Ana R.', time: '1 h ago', ok: true },
|
||||
{ project: 'permit-portal', env: 'preview', by: 'Circuit agent', time: '3 h ago', ok: false },
|
||||
{ project: 'case-intake-web', env: 'staging', by: 'Mats K.', time: 'yesterday', ok: true },
|
||||
]
|
||||
|
||||
const team = {
|
||||
members: ['MK', 'AR', 'JT', 'SB'],
|
||||
extraCount: 3,
|
||||
activity: 'Ana approved the merge request for classify-case an hour ago.',
|
||||
}
|
||||
|
||||
const budget = { used: 14_250, total: 20_000, currency: 'kr' }
|
||||
|
||||
const insight = {
|
||||
title: 'Memory pressure on session-cache',
|
||||
body: 'Two pods restarted after a memory spike at 09:42. Raising the limit to 512 Mi keeps headroom for the morning peak.',
|
||||
action: 'Raise limit to 512 Mi',
|
||||
}
|
||||
|
||||
const routes = {
|
||||
'/api/stats': stats,
|
||||
'/api/resources': resources,
|
||||
'/api/deploys': deploys,
|
||||
'/api/team': team,
|
||||
'/api/budget': budget,
|
||||
'/api/insight': insight,
|
||||
}
|
||||
|
||||
const PORT = 8787
|
||||
|
||||
export function startMockServer(port = PORT) {
|
||||
const server = createServer((req, res) => {
|
||||
const respond = (status, body) => {
|
||||
res.writeHead(status, { 'content-type': 'application/json' })
|
||||
res.end(JSON.stringify(body))
|
||||
}
|
||||
setTimeout(() => {
|
||||
const body = routes[req.url]
|
||||
if (req.method === 'GET' && body !== undefined) respond(200, body)
|
||||
else respond(404, { error: 'Not found', method: req.method, path: req.url })
|
||||
}, 350)
|
||||
})
|
||||
server.listen(port)
|
||||
console.log(`[mock-api] listening on http://localhost:${port}`)
|
||||
return server
|
||||
}
|
||||
Reference in new issue
Block a user