Download tasks/hipcamp/solution/site/implementation/clone/worker/index.ts from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/hipcamp/solution/site/implementation/clone/worker/index.ts
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/hipcamp/solution/site/implementation/clone/worker/index.ts
-
curl -L -o index.ts https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/hipcamp/solution/site/implementation/clone/worker/index.ts
2.11 kB
| import handler from "vinext/server/app-router-entry"; | |
| type AssetFetcher = { | |
| fetch(request: Request): Promise<Response>; | |
| }; | |
| interface Env { | |
| ASSETS: AssetFetcher; | |
| DB?: unknown; | |
| } | |
| interface ExecutionContext { | |
| waitUntil(promise: Promise<unknown>): void; | |
| passThroughOnException(): void; | |
| } | |
| function traceId(request: Request) { | |
| const incoming = request.headers.get("x-request-id")?.trim(); | |
| if (incoming && /^[A-Za-z0-9._:-]{1,128}$/.test(incoming)) return incoming; | |
| return `req_${crypto.randomUUID()}`; | |
| } | |
| const contentSecurityPolicy = [ | |
| "default-src 'self'", | |
| "base-uri 'self'", | |
| "frame-ancestors 'none'", | |
| "form-action 'self'", | |
| "object-src 'none'", | |
| "img-src 'self' data:", | |
| "font-src 'self' data:", | |
| "style-src 'self' 'unsafe-inline'", | |
| "script-src 'self' 'unsafe-inline' 'unsafe-eval'", | |
| "connect-src 'self' ws: wss:", | |
| ].join("; "); | |
| function attachWorkerHeaders(response: Response, requestId: string) { | |
| response.headers.set("x-request-id", requestId); | |
| response.headers.set("x-content-type-options", "nosniff"); | |
| response.headers.set("x-frame-options", "DENY"); | |
| response.headers.set("referrer-policy", "strict-origin-when-cross-origin"); | |
| response.headers.set("permissions-policy", "camera=(), microphone=(), geolocation=()"); | |
| response.headers.set("cross-origin-opener-policy", "same-origin"); | |
| response.headers.set("cross-origin-resource-policy", "same-origin"); | |
| response.headers.set("content-security-policy", contentSecurityPolicy); | |
| return response; | |
| } | |
| const worker = { | |
| async fetch(request: Request, env: Env, ctx: ExecutionContext) { | |
| const requestId = traceId(request); | |
| const headers = new Headers(request.headers); | |
| headers.set("x-request-id", requestId); | |
| const tracedRequest = new Request(request, { headers }); | |
| const response = await handler.fetch(tracedRequest, env, ctx); | |
| const tracedResponse = new Response(response.body, { | |
| status: response.status, | |
| statusText: response.statusText, | |
| headers: response.headers, | |
| }); | |
| return attachWorkerHeaders(tracedResponse, requestId); | |
| }, | |
| }; | |
| export default worker; | |