Ops-dashboard/app/caddy/page.tsx
Scrum4Me Agent 30f1b452a8 feat(caddy): /caddy page with config view and cert status table
- app/caddy/page.tsx: server component fetches caddy_show_config (shiki-highlighted Caddyfile) and caddy_list_certs (parsed CertInfo[])
- app/caddy/_components/caddy-view.tsx: client component shows cert table (domain, issuer CN, notBefore, notAfter) with Valid/Expiring soon/Expired badges; auto-refreshes every 60 seconds

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-13 17:48:51 +02:00

61 lines
1.9 KiB
TypeScript

import { redirect } from 'next/navigation'
import { codeToHtml } from 'shiki'
import { getCurrentUser } from '@/lib/session'
import { execAgent } from '@/lib/agent-client'
import { parseCertList, type CertInfo } from '@/lib/parse-caddy'
import CaddyView from './_components/caddy-view'
export const dynamic = 'force-dynamic'
export default async function CaddyPage() {
const user = await getCurrentUser()
if (!user) redirect('/login')
let configHtml = ''
let configError: string | null = null
try {
const raw = await execAgent('caddy_show_config')
configHtml = await codeToHtml(raw || '# (empty)', {
lang: 'caddyfile',
theme: 'github-dark',
})
} catch (err) {
configError = err instanceof Error ? err.message : 'failed'
}
let initialCerts: CertInfo[] = []
let certsError: string | null = null
try {
const raw = await execAgent('caddy_list_certs')
initialCerts = parseCertList(raw)
} catch (err) {
certsError = err instanceof Error ? err.message : 'failed'
}
return (
<div className="min-h-screen bg-background p-6">
<div className="mx-auto max-w-6xl space-y-8">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Caddy</h1>
<p className="text-sm text-muted-foreground">Config view and TLS certificate status</p>
</div>
<section className="space-y-3">
<h2 className="text-lg font-medium tracking-tight">Caddyfile</h2>
{configError ? (
<div className="rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive">
{configError}
</div>
) : (
<div
className="overflow-x-auto rounded-lg border border-border text-sm [&>pre]:p-4"
dangerouslySetInnerHTML={{ __html: configHtml }}
/>
)}
</section>
<CaddyView initialCerts={initialCerts} certsError={certsError} />
</div>
</div>
)
}