The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
| 1 | // The playground's prerender Worker and entry Worker in one: alchemy has no |
| 2 | // separate prerender Worker, so the build's preview server renders |
| 3 | // `/prerendered` from the entry Worker itself. |
| 4 | interface Env { |
| 5 | AUXILIARY_WORKER: Fetcher; |
| 6 | } |
| 7 | |
| 8 | export default { |
| 9 | async fetch(request, env) { |
| 10 | // The build must ship this declaration as written |
| 11 | using _scope = { [Symbol.dispose]() {} }; |
| 12 | const url = new URL(request.url); |
| 13 | |
| 14 | if (url.pathname === "/prerendered") { |
| 15 | const auxiliaryResponse = await env.AUXILIARY_WORKER.fetch(request); |
| 16 | const auxiliaryText = await auxiliaryResponse.text(); |
| 17 | return new Response( |
| 18 | `\ |
| 19 | <!DOCTYPE html> |
| 20 | <html lang="en"> |
| 21 | <head> |
| 22 | <meta charset="UTF-8"> |
| 23 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 24 | <title>Pre-rendering</title> |
| 25 | </head> |
| 26 | <body> |
| 27 | <h1>Pre-rendered HTML ${auxiliaryText}</h1> |
| 28 | </body> |
| 29 | </html>`, |
| 30 | { |
| 31 | headers: { "Content-Type": "text/html" }, |
| 32 | }, |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | if (url.pathname === "/hello") { |
| 37 | return new Response("Hello world"); |
| 38 | } |
| 39 | |
| 40 | return new Response(null, { status: 404 }); |
| 41 | }, |
| 42 | } satisfies ExportedHandler<Env>; |