1// `GET /identity.ts`: the machine-identity script, served so an agent on2// any machine can `deno run -A https://<host>/identity.ts`. The content3// type must say TypeScript (a static `.ts` would be served as MPEG-TS).4import { define } from "../utils.ts";56let cached: string | null = null;78async function source(): Promise<string> {9 if (cached) return cached;10 // the server runs from the site directory (a checkout or /app/site)11 for (12 const p of [13 "scripts/identity.ts",14 new URL("../scripts/identity.ts", import.meta.url).pathname,15 ]16 ) {17 try {18 cached = await Deno.readTextFile(p);19 return cached;20 } catch {21 // next22 }23 }24 throw new Error("identity script not found");25}2627export const handler = define.handlers({28 async GET() {29 return new Response(await source(), {30 headers: {31 "Content-Type": "application/typescript; charset=utf-8",32 "Cache-Control": "public, max-age=300",33 },34 });35 },36});