Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/web/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const rootEnv = new URL('../../.env.local', import.meta.url);
if (existsSync(rootEnv)) process.loadEnvFile(rootEnv);

const nextConfig: NextConfig = {
// Every report page has a JSON twin at the same address plus .json. Domains have dots, so it
// can't be its own [domain] segment: it's rewritten to a route handler instead.
async rewrites() {
return [{ source: '/s/:domain(.+)\\.json', destination: '/api/reports/:domain' }];
},
// The workspace packages ship TypeScript source, so Next compiles them like app code.
// Only loaded when self-hosted with Chromium installed; never bundled.
serverExternalPackages: ['playwright-core'],
Expand Down
10 changes: 10 additions & 0 deletions apps/web/src/app/api/reports/[domain]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { reportJson } from '../../../../lib/report-json.ts';
import { getStore } from '../../../../lib/services.ts';

// /s/<domain>.json lands here (see next.config.ts): the report page's JSON twin.
export async function GET(request: Request, { params }: { params: Promise<{ domain: string }> }) {
const domain = decodeURIComponent((await params).domain).toLowerCase();
const scan = await getStore().latestScan(domain);
const { status, body, headers } = reportJson(domain, scan, new URL(request.url).origin);
return Response.json(body, { status, headers });
}
14 changes: 14 additions & 0 deletions apps/web/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,14 @@ details[open] > .tech-row {
display: contents;
}

.json-link {
align-self: center;
margin-right: var(--space-2);
font-family: var(--font-mono);
font-size: var(--text-data);
color: var(--ink-3);
}

.warn-text {
color: var(--warn-ink);
}
Expand Down Expand Up @@ -818,6 +826,12 @@ details[open] > .tech-row {
grid-template-columns: 1fr 1fr;
}

.json-link {
grid-column: 1 / -1;
align-self: start;
margin: 0 0 var(--space-1);
}

.actions .button {
width: 100%;
height: var(--control-md);
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/app/s/[domain]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ interface Props {
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { domain } = await params;
return { title: `${decodeURIComponent(domain)} · stackprobe` };
const name = decodeURIComponent((await params).domain).toLowerCase();
return {
title: `${name} · stackprobe`,
// Agents can find the report as data from the page itself.
alternates: { types: { 'application/json': `/s/${encodeURIComponent(name)}.json` } },
};
}

export default async function ScanPage({ params, searchParams }: Props) {
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/app/s/[domain]/report-sections.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ describe('ReportView', () => {
expect(html).not.toContain('framer header');
});

test('says which checks ran and offers copy and scan again', () => {
test('says which checks ran and offers the JSON twin, copy and scan again', () => {
const html = render();
expect(html).toContain('Checks that ran: HTTP and a real browser.');
expect(html).toContain('Fingerprints <span class="mono">abc123</span>');
expect(html).toContain(
'<a class="json-link" href="/s/acme.test.json" type="application/json">acme.test.json</a>',
);
expect(html).toContain('Copy link');
expect(html).toContain('Scan again');
});
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/app/s/[domain]/report-sections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ export function ReportView({
</p>
</div>
<div className="actions">
<a
className="json-link"
href={`/s/${encodeURIComponent(scan.domain)}.json`}
type="application/json"
>
{scan.domain}.json
</a>
<CopyLink />
<form action={rescanAction}>
<input type="hidden" name="url" value={scan.url} />
Expand Down
73 changes: 73 additions & 0 deletions apps/web/src/lib/report-json.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Report, type ScanRecord, scan } from '@drippa/stackprobe-core';
import { describe, expect, test } from 'vitest';
import { DOMAINS_DIR, loadRecording, ReplayNet } from '../../../../packages/core/test/fixtures.ts';
import { reportJson } from './report-json.ts';

const origin = 'https://stackprobe.tech';

// A real report: the recorded drippa.ai scan, replayed without the network.
async function fixtureScan(): Promise<ScanRecord> {
const recording = loadRecording('drippa.ai', DOMAINS_DIR);
const report = await scan(recording.url, {
net: new ReplayNet(recording),
now: () => new Date(recording.recordedAt),
});
return {
id: 'scan-1',
domain: 'drippa.ai',
url: recording.url,
status: 'done',
createdAt: '2026-10-07T12:00:00.000Z',
finishedAt: '2026-10-07T12:00:28.000Z',
report,
};
}

describe('reportJson', () => {
test('a finished scan: its report, valid against schema/report.v1.json, and the scan around it', async () => {
const record = await fixtureScan();
const { status, body, headers } = reportJson('drippa.ai', record, origin);
expect(status).toBe(200);
expect(body).toMatchObject({
scanId: 'scan-1',
domain: 'drippa.ai',
status: 'done',
createdAt: '2026-10-07T12:00:00.000Z',
finishedAt: '2026-10-07T12:00:28.000Z',
page: 'https://stackprobe.tech/s/drippa.ai',
});
// The committed JSON Schema is generated from this zod schema, and core's tests keep the two
// equal, so parsing with it is validating against the file.
const report = 'report' in body ? body.report : null;
expect(Report.parse(JSON.parse(JSON.stringify(report)))).toEqual(record.report);
expect(headers['cache-control']).toMatch(/s-maxage=300/);
expect(headers['access-control-allow-origin']).toBe('*');
});

test('a running scan: its status, no report yet, cached only for seconds', () => {
const running: ScanRecord = {
id: 'scan-2',
domain: 'acme.test',
url: 'https://acme.test/',
status: 'running',
createdAt: '2026-10-07T12:00:00.000Z',
finishedAt: null,
report: null,
};
const { status, body, headers } = reportJson('acme.test', running, origin);
expect(status).toBe(200);
expect(body).toMatchObject({ status: 'running', report: null, finishedAt: null });
expect(headers['cache-control']).toBe('public, max-age=0, s-maxage=2');
});

test('an unknown domain: 404, with where to scan it', () => {
const { status, body } = reportJson('new.test', null, origin);
expect(status).toBe(404);
expect(body).toEqual({
error: 'not_scanned',
domain: 'new.test',
message: "new.test hasn't been scanned yet. Open the page to scan it.",
page: 'https://stackprobe.tech/s/new.test',
});
});
});
72 changes: 72 additions & 0 deletions apps/web/src/lib/report-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { Report, ScanRecord, ScanStatus } from '@drippa/stackprobe-core';

// The JSON twin of a report page, /s/<domain>.json: the domain's newest scan, as data. The same
// fields the MCP get_scan tool returns, plus the scan's address and times. `report` alone
// matches schema/report.v1.json; it's null while the scan runs.
export interface ReportJson {
scanId: string;
domain: string;
url: string;
status: ScanStatus;
createdAt: string;
finishedAt: string | null;
// The report page for people.
page: string;
report: Report | null;
}

export interface NotScannedJson {
error: 'not_scanned';
domain: string;
message: string;
page: string;
}

export interface JsonResponse {
status: number;
body: ReportJson | NotScannedJson;
headers: Record<string, string>;
}

// Finished scans never change, but a new scan can replace them as the newest; running ones
// change every few seconds.
const CACHE = {
finished: 'public, max-age=60, s-maxage=300, stale-while-revalidate=3600',
running: 'public, max-age=0, s-maxage=2',
missing: 'public, max-age=0, s-maxage=5',
};

export function reportJson(domain: string, scan: ScanRecord | null, origin: string): JsonResponse {
const page = `${origin}/s/${encodeURIComponent(domain)}`;
// Reading is free and public: any site or agent may fetch it.
const headers = { 'access-control-allow-origin': '*' };
if (!scan) {
return {
status: 404,
headers: { ...headers, 'cache-control': CACHE.missing },
body: {
error: 'not_scanned',
domain,
message: `${domain} hasn't been scanned yet. Open the page to scan it.`,
page,
},
};
}
return {
status: 200,
headers: {
...headers,
'cache-control': scan.status === 'running' ? CACHE.running : CACHE.finished,
},
body: {
scanId: scan.id,
domain: scan.domain,
url: scan.url,
status: scan.status,
createdAt: scan.createdAt,
finishedAt: scan.finishedAt,
page,
report: scan.report,
},
};
}
Loading