diff options
| author | Joe Mou <dev@mou.fo> | 2026-09-18 07:27:21 +0100 |
|---|---|---|
| committer | Joe Mou <dev@mou.fo> | 2026-09-18 07:27:21 +0100 |
| commit | 9659525bf2387af6deab9d401784b94b1f44d395 (patch) | |
| tree | c67dc1dd05bf2a8fa48dc123d6353d255a658ef1 /cgithub/src/worker.ts | |
| parent | 9819d8e5504d6f03d27ec6b8786eec8fe5a752a5 (diff) | |
| parent | 01494e6fa1345a509560e5e19a7f08cb2aac5cc8 (diff) | |
Diffstat (limited to 'cgithub/src/worker.ts')
| -rw-r--r-- | cgithub/src/worker.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/cgithub/src/worker.ts b/cgithub/src/worker.ts new file mode 100644 index 0000000..e59c690 --- /dev/null +++ b/cgithub/src/worker.ts @@ -0,0 +1,30 @@ +// 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/build.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 }); + +// Templates name each other as siblings ("./_tree") or from the views root +// ("/layouts/base.eta"); either way the name is the path under views/ that +// scripts/build.ts keyed the template by. +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); |
