diff options
| author | Joe Mou <dev@mou.fo> | 2026-07-15 02:08:17 -0400 |
|---|---|---|
| committer | Joe Mou <dev@mou.fo> | 2026-07-15 02:08:29 -0400 |
| commit | 9b556ffe6c0c0528697e15f7f4f35107de212ce1 (patch) | |
| tree | 7f87bd7d58c4bc9a640a669fa314fec6c49c82df /cgithub/src/worker.ts | |
| parent | 9fbb5f0d68a131b55bc172d46b75705f2842af04 (diff) | |
Add Cloudflare Workers deployment target
Split routes into a shared createApp() (src/app.ts) used by both the
Node entry (src/index.ts) and a new Workers entry (src/worker.ts).
Workers disallow runtime code generation, so scripts/compile-views.ts
precompiles the Eta templates into src/views.generated.ts and rendering
switches from renderAsync to the sync render. Static files move to
public/static so Workers Static Assets can serve them; the Node build
and serveStatic root are updated to match.
Deploy with pnpm run deploy:cf, local dev with pnpm run dev:cf.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'cgithub/src/worker.ts')
| -rw-r--r-- | cgithub/src/worker.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/cgithub/src/worker.ts b/cgithub/src/worker.ts new file mode 100644 index 0000000..024b01a --- /dev/null +++ b/cgithub/src/worker.ts @@ -0,0 +1,27 @@ +// Cloudflare Workers entry point. Static files under public/ are served by +// Workers Static Assets before the worker runs (see wrangler.jsonc). +import { Eta } from "eta"; +import { createApp } from "./app.ts"; +import { views } from "./views.generated.ts"; + +// Workers disallow runtime code generation, so templates are precompiled by +// scripts/compile-views.ts and preloaded into Eta's cache here. With +// cache: true, Eta serves them from the cache and never compiles. +const eta = new Eta({ cache: true }); + +eta.resolvePath = (templatePath: string) => { + let name = templatePath.replace(/^\.\//, ""); + if (!name.endsWith(".eta")) name += ".eta"; + return name; +}; + +// Only reached on a cache miss, i.e. a template missing from the build. +eta.readFile = (path: string) => { + throw new Error(`Unknown template: ${path}`); +}; + +for (const [name, fn] of Object.entries(views)) { + eta.loadTemplate(name, fn); +} + +export default createApp(eta); |
