Skip to content

armgit / AiSOC

Public Imported from GitHub
0

Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.

fix(web): SSR /cases with live backend data so console no longer shows mocks

Beenu Arora7414bfe5e01e
diff --git a/apps/web/src/app/(app)/cases/page.tsx b/apps/web/src/app/(app)/cases/page.tsx
index f23a43fac..8e6697d6f 100644
--- a/apps/web/src/app/(app)/cases/page.tsx
+++ b/apps/web/src/app/(app)/cases/page.tsx
@@ -1,9 +1,55 @@
import { CasesView } from '@/components/cases/CasesView';
+import {
+ normalizeCasesResponse,
+ type CasesResponse,
+} from '@/lib/api';
export const metadata = {
title: 'Cases | AiSOC',
};
-export default function CasesPage() {
- return <CasesView />;
+// The /cases page must reflect the current state of the backend on every
+// request; static prerendering and CDN caching previously caused stale mock
+// data to be served when client-side hydration failed.
+export const dynamic = 'force-dynamic';
+export const revalidate = 0;
+export const fetchCache = 'force-no-store';
+
+const DEFAULT_TENANT_ID = '00000000-0000-0000-0000-000000000001';
+
+function resolveServerApiBase(): string {
+ // Prefer the in-cluster mesh URL when running on Fly so SSR doesn't depend
+ // on public DNS or TLS. Fall back to the public API base for local dev.
+ const internal = process.env.API_URL?.trim();
+ if (internal) return internal.replace(/\/+$/, '');
+ const publicBase = process.env.NEXT_PUBLIC_API_URL?.trim();
+ if (publicBase) return publicBase.replace(/\/+$/, '');
+ return '';
+}
+
+async function loadInitialCases(): Promise<CasesResponse | null> {
+ const base = resolveServerApiBase();
+ if (!base) return null;
+ const tenantId =
+ process.env.NEXT_PUBLIC_TENANT_ID?.trim() || DEFAULT_TENANT_ID;
+ try {
+ const res = await fetch(`${base}/api/v1/cases`, {
+ headers: {
+ Accept: 'application/json',
+ 'X-Tenant-Id': tenantId,
+ },
+ cache: 'no-store',
+ next: { revalidate: 0 },
+ });
+ if (!res.ok) return null;
+ const raw = await res.json();
+ return normalizeCasesResponse(raw);
+ } catch {
+ return null;
+ }
+}
+
+export default async function CasesPage() {
+ const initialCases = await loadInitialCases();
+ return <CasesView initialCases={initialCases ?? undefined} />;
}
diff --git a/apps/web/src/components/cases/CasesView.tsx b/apps/web/src/components/cases/CasesView.tsx
index 88adf9172..31ded8638 100644
--- a/apps/web/src/components/cases/CasesView.tsx
+++ b/apps/web/src/components/cases/CasesView.tsx
@@ -4,7 +4,7 @@ import { useState } from 'react';
import useSWR from 'swr';
import Link from 'next/link';
import toast from 'react-hot-toast';
-import { casesApi, type Case } from '@/lib/api';
+import { casesApi, type Case, type CasesResponse } from '@/lib/api';
import { clsx } from 'clsx';
import { format } from 'date-fns';
@@ -126,21 +126,33 @@ function CaseCard({ c }: { c: Case }) {
type FilterStatus = Case['status'] | 'all';
-export function CasesView() {
+interface CasesViewProps {
+ /**
+ * Optional pre-fetched cases from a Server Component. When provided, these
+ * are rendered on first paint (no flash of mock data) and SWR revalidates
+ * in the background. When omitted (e.g. dev/local without API access),
+ * deterministic mock data is used so the layout stays stable for SSR.
+ */
+ initialCases?: CasesResponse;
+}
+
+export function CasesView({ initialCases }: CasesViewProps = {}) {
const [statusFilter, setStatusFilter] = useState<FilterStatus>('all');
const [severityFilter, setSeverityFilter] = useState<Case['severity'] | 'all'>('all');
const [search, setSearch] = useState('');
+ const fallback: CasesResponse = initialCases ?? {
+ cases: MOCK_CASES,
+ total: MOCK_CASES.length,
+ page: 1,
+ pageSize: MOCK_CASES.length,
+ };
+
const { data: casesData, isLoading } = useSWR(
['cases', statusFilter, severityFilter],
() => casesApi.list({ status: statusFilter !== 'all' ? statusFilter : undefined }),
{
- fallbackData: {
- cases: MOCK_CASES,
- total: MOCK_CASES.length,
- page: 1,
- pageSize: MOCK_CASES.length,
- },
+ fallbackData: fallback,
}
);
diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts
index 5a71636be..58a732b97 100644
--- a/apps/web/src/lib/api.ts
+++ b/apps/web/src/lib/api.ts
@@ -704,7 +704,7 @@ function normalizeCase(raw: unknown): Case {
};
}
-function normalizeCasesResponse(raw: unknown, filters: CaseFilters = {}): CasesResponse {
+export function normalizeCasesResponse(raw: unknown, filters: CaseFilters = {}): CasesResponse {
// The API may return either a bare array of cases or an envelope shape.
if (Array.isArray(raw)) {
const cases = raw.map(normalizeCase);