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, 06:00 UTC
| 1 | import subpathHtml from "#html"; |
| 2 | import subpathHtmlWithExt from "#modules/html-example.html"; |
| 3 | // Mirrors `@cloudflare/vite-plugin`'s `playground/additional-modules`. |
| 4 | import bin from "./modules/bin-example.bin"; |
| 5 | import html from "./modules/html-example.html"; |
| 6 | import sql from "./modules/sql-example.sql"; |
| 7 | import text from "./modules/text-example.txt"; |
| 8 | import text2 from "./modules/text__example__2.txt"; |
| 9 | import wasm from "./modules/wasm-example.wasm"; |
| 10 | import init from "./modules/wasm-example.wasm?init"; |
| 11 | import wasmWithModuleParam from "./modules/wasm-example.wasm?module"; |
| 12 | |
| 13 | interface Instance { |
| 14 | exports: { |
| 15 | add(a: number, b: number): number; |
| 16 | }; |
| 17 | } |
| 18 | |
| 19 | export default { |
| 20 | async fetch(request) { |
| 21 | const url = new URL(request.url); |
| 22 | |
| 23 | switch (url.pathname) { |
| 24 | case "/bin": { |
| 25 | return Response.json({ byteLength: bin.byteLength }); |
| 26 | } |
| 27 | case "/html": { |
| 28 | return new Response(String(html), { headers: { "Content-Type": "text/html" } }); |
| 29 | } |
| 30 | case "/subpath-html": { |
| 31 | return new Response(String(subpathHtml), { |
| 32 | headers: { "Content-Type": "text/html" }, |
| 33 | }); |
| 34 | } |
| 35 | case "/subpath-html-with-ext": { |
| 36 | return new Response(String(subpathHtmlWithExt), { |
| 37 | headers: { "Content-Type": "text/html" }, |
| 38 | }); |
| 39 | } |
| 40 | case "/text": { |
| 41 | return new Response(text); |
| 42 | } |
| 43 | case "/text2": { |
| 44 | return new Response(text2); |
| 45 | } |
| 46 | case "/sql": { |
| 47 | return new Response(sql); |
| 48 | } |
| 49 | case "/wasm": { |
| 50 | const instance = (await WebAssembly.instantiate(wasm)) as Instance; |
| 51 | const result = instance.exports.add(3, 4); |
| 52 | |
| 53 | return Response.json({ result }); |
| 54 | } |
| 55 | case "/wasm-with-module-param": { |
| 56 | const instance = (await WebAssembly.instantiate(wasmWithModuleParam)) as Instance; |
| 57 | const result = instance.exports.add(5, 6); |
| 58 | |
| 59 | return Response.json({ result }); |
| 60 | } |
| 61 | case "/wasm-with-init-param": { |
| 62 | const instance = (await init()) as Instance; |
| 63 | const result = instance.exports.add(7, 8); |
| 64 | |
| 65 | return Response.json({ result }); |
| 66 | } |
| 67 | default: { |
| 68 | return new Response(null, { status: 404 }); |
| 69 | } |
| 70 | } |
| 71 | }, |
| 72 | } satisfies ExportedHandler; |