@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, 07:15 UTC

main
ts 58 lines 1.83 KB
Raw
1 // Mirrors `@cloudflare/vite-plugin`'s `playground/module-resolution` (without
2 // its third-party package routes).
3 const modules = import.meta.glob("../src/**/*.ts");
4
5 export default {
6 async fetch(request) {
7 const { pathname } = new URL(request.url);
8
9 if (pathname === "/@alias/test") {
10 const { test } = await import("@alias/test");
11 return test();
12 }
13
14 if (pathname === "/virtual-module") {
15 // @ts-expect-error virtual module
16 const virtualModule = await import("virtual:module");
17 return new Response(virtualModule.default);
18 }
19
20 if (pathname === "/optimize-deps/exclude") {
21 const { virtualExport } = await import(
22 // @ts-expect-error virtual module
23 "@playground/module-resolution-excludes"
24 );
25
26 return new Response(virtualExport);
27 }
28
29 const filePath = `${pathname.replace(/^\//, "./")}.ts`;
30
31 if (modules[filePath]) {
32 const mod = await modules[filePath]();
33 return Response.json((mod as { default: unknown }).default);
34 }
35
36 const html = `<!DOCTYPE html>
37 <body>
38 <h1>Module Resolution App</h1>
39 <p>
40 This app is an example/test for dependencies module resolution being performed in the Cloudflare environment (inside the workerd runtime)
41 </p>
42 <hr />
43 <h2>Available Routes</h2>
44 <ul>
45 ${[...Object.keys(modules), "/@alias/test", "optimize-deps/exclude"]
46 .map((path) => path.replace(/^\.\//, "/").replace(/\.ts$/, ""))
47 .map((route) => ` <li><a href="${route}">${route}</a></li>`)
48 .join("\n")}
49 </ul>
50 </body>`;
51
52 return new Response(html, {
53 headers: {
54 "content-type": "text/html;charset=UTF-8",
55 },
56 });
57 },
58 } satisfies ExportedHandler;