1. Configure Worker Secrets & Environment Variables
Copy your site-scoped `PRISMUV_EDGE_SECRET` (`pve_...`) from PrismUV Dashboard -> Install & Export -> Site Credentials, and store it securely using Wrangler.
# Store per-site edge secret cleanly (never hardcode in Git) npx wrangler secret put PRISMUV_EDGE_SECRET # wrangler.toml [vars] [vars] PRISMUV_UPSTREAM = "https://prismuv.com" PRISMUV_SITE_ID = "YOUR_SITE_ID"
2. Mount the Fail-Open /_t/* Proxy & AI Crawler Beacon
Handle `/_t/*` first-party requests by proxying cleanly with strict header forwarding (`CF-Connecting-IP`, `CF-IPCountry`), and enqueue non-blocking `/t/edge` logs when AI/Search bots request HTML or `/llms*.txt` documents.
const BOT_RE = /(oai-searchbot|chatgpt-user|gptbot|claudebot|claude-searchbot|claude-user|perplexitybot|googlebot|bingbot)/i;
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url);
// 1. First-party /_t/* proxy
if (url.pathname.startsWith('/_t/')) {
const upstreamPath = url.pathname.replace(/^\/_t/, '');
const target = new URL(upstreamPath + url.search, env.PRISMUV_UPSTREAM);
try {
const resp = await fetch(target.toString(), {
method: request.method,
headers: request.headers,
body: request.method === 'GET' || request.method === 'HEAD' ? undefined : request.body,
});
return resp;
} catch {
return new Response(null, { status: 204 }); // Fail-open
}
}
// 2. Serve origin / static assets and log AI crawlers without blocking TTFB
const response = await env.ASSETS.fetch(request);
const ua = request.headers.get('user-agent') || '';
if (ua && BOT_RE.test(ua) && response.status < 400) {
ctx.waitUntil(
fetch(`${env.PRISMUV_UPSTREAM}/t/edge`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Prism-Edge-Secret': env.PRISMUV_EDGE_SECRET || '',
},
body: JSON.stringify({
site_id: env.PRISMUV_SITE_ID,
path: url.pathname,
status_code: response.status,
ua: ua.slice(0, 300),
country: request.headers.get('cf-ipcountry') || '',
ip: request.headers.get('cf-connecting-ip') || '',
}),
}).catch(() => {})
);
}
return response;
},
};3. Reference the First-Party Script in HTML
Load `/_t/f.js` from your own apex origin with `data-site` pointing to your site ID and `data-endpoint="/_t"` so zero cross-origin analytics calls appear.
<script defer src="/_t/f.js" data-site="YOUR_SITE_ID" data-endpoint="/_t" data-release="v1.0.0" ></script>