mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
3d784a5edb
* cookbook md * Update proxy.ts
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { siteId } from '@/geistdocs';
|
|
|
|
const PLATFORM_URL = 'https://geistdocs.com/md-tracking';
|
|
|
|
type TrackMdRequestParams = {
|
|
path: string;
|
|
userAgent: string | null;
|
|
referer: string | null;
|
|
acceptHeader: string | null;
|
|
/** How the markdown was requested. */
|
|
requestType?: 'md-url' | 'header-negotiated' | 'agent-rewrite';
|
|
/** Which AI-agent detection signal triggered the rewrite. */
|
|
detectionMethod?: 'ua-match' | 'signature-agent' | 'heuristic' | null;
|
|
};
|
|
|
|
/**
|
|
* Track a markdown page request via the geistdocs platform.
|
|
* Fire-and-forget: errors are logged but don't affect the response.
|
|
*/
|
|
export async function trackMdRequest({
|
|
path,
|
|
userAgent,
|
|
referer,
|
|
acceptHeader,
|
|
requestType,
|
|
detectionMethod,
|
|
}: TrackMdRequestParams): Promise<void> {
|
|
try {
|
|
const response = await fetch(PLATFORM_URL, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
path,
|
|
siteId: siteId ?? 'geistdocs-unknown',
|
|
userAgent,
|
|
referer,
|
|
acceptHeader,
|
|
requestType,
|
|
detectionMethod,
|
|
}),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
console.error(
|
|
'MD tracking failed:',
|
|
response.status,
|
|
await response.text()
|
|
);
|
|
}
|
|
} catch (error) {
|
|
console.error('MD tracking error:', error);
|
|
}
|
|
}
|