| 1 | // Guarded dynamic import of `cloudflare:workers` (the same trick waku's own |
| 2 | // adapter uses): the portable way to reach Worker bindings from modules that |
| 3 | // must also load outside a Cloudflare environment — waku's SSG step renders |
| 4 | // static pages in Node, where a top-level `import { env } from |
| 5 | // "cloudflare:workers"` cannot resolve. |
| 6 | const DO_NOT_BUNDLE = ""; |
| 7 | |
| 8 | export async function readEnv(): Promise<Record<string, unknown>> { |
| 9 | try { |
| 10 | const mod = await import( |
| 11 | /* @vite-ignore */ DO_NOT_BUNDLE + "cloudflare:workers" |
| 12 | ); |
| 13 | return mod.env as Record<string, unknown>; |
| 14 | } catch { |
| 15 | return {}; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | export async function readMessage(): Promise<string> { |
| 20 | const env = await readEnv(); |
| 21 | return String(env.MESSAGE ?? "unset"); |
| 22 | } |