@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 60 lines 2.1 KB
Raw
1 import subpathHtmlWithExt from "#modules/html-example.html";
2 import bin from "./modules/bin-example.bin";
3 import html from "./modules/html-example.html";
4 import sql from "./modules/sql-example.sql";
5 import text from "./modules/text-example.txt";
6 import text2 from "./modules/text__example__2.txt";
7 import wasm from "./modules/wasm-example.wasm";
8 import init from "./modules/wasm-example.wasm?init";
9 import wasmWithModuleParam from "./modules/wasm-example.wasm?module";
10
11 // Removed because this seems to be a Vite-specific feature, rather than a Rolldown feature.
12 // TODO: Find out if this works with Vite.
13 // import subpathHtml from "#html";
14
15 interface Instance {
16 exports: {
17 add(a: number, b: number): number;
18 };
19 }
20
21 export default {
22 async fetch(request: Request) {
23 const url = new URL(request.url);
24
25 switch (url.pathname) {
26 case "/bin":
27 return Response.json({ byteLength: bin.byteLength });
28 case "/html":
29 return new Response(html, { headers: { "Content-Type": "text/html" } });
30 // case "/subpath-html":
31 // return new Response(subpathHtml, {
32 // headers: { "Content-Type": "text/html" },
33 // });
34 case "/subpath-html-with-ext":
35 return new Response(subpathHtmlWithExt, {
36 headers: { "Content-Type": "text/html" },
37 });
38 case "/text":
39 return new Response(text);
40 case "/text2":
41 return new Response(text2);
42 case "/sql":
43 return new Response(sql);
44 case "/wasm": {
45 const instance = (await WebAssembly.instantiate(wasm)) as Instance;
46 return Response.json({ result: instance.exports.add(3, 4) });
47 }
48 case "/wasm-with-module-param": {
49 const instance = (await WebAssembly.instantiate(wasmWithModuleParam)) as Instance;
50 return Response.json({ result: instance.exports.add(5, 6) });
51 }
52 case "/wasm-with-init-param": {
53 const instance = (await init()) as Instance;
54 return Response.json({ result: instance.exports.add(7, 8) });
55 }
56 default:
57 return new Response(null, { status: 404 });
58 }
59 },
60 } satisfies ExportedHandler;