From 544cf0043fe7a14639cf91ca7bd90ace2c699de5 Mon Sep 17 00:00:00 2001 From: Sebastien Ringrose Date: Mon, 22 Jul 2024 16:02:42 +0100 Subject: [PATCH] fix: wrangler env --- package.json | 2 +- scripts/wrangler/main.ts | 11 +++++------ wrangler.toml | 9 ++++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 717a4fec..dd5f3a8b 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "dev:build": "esbuild --bundle --sourcemap --target=es2020 --platform=browser --format=esm --outdir=./example/preactSSR/dist/pages --external:esbuild --external:htm/preact --external:preact --external:preact/hooks --external:preact-render-to-string --watch=forever ./example/preactSSR/src/pages/*.ts", "dev:deno": "deno run -A --watch scripts/deno/main.ts", "dev:bun": "bun run --watch scripts/bun/main.ts", - "dev:wrangler": "wrangler dev scripts/wrangler/main.ts" + "dev:wrangler": "wrangler -e dev dev scripts/wrangler/main.ts" }, "repository": { "type": "git", diff --git a/scripts/wrangler/main.ts b/scripts/wrangler/main.ts index f1aa9b5b..0b2d8751 100644 --- a/scripts/wrangler/main.ts +++ b/scripts/wrangler/main.ts @@ -1,13 +1,12 @@ import router from "../../example/preactSSR/router.ts"; -router.middleware.unshift((ctx) => { - ctx.state.env = env; -}); - export default { - fetch(request: Request) { + fetch(request: Request, env: Record) { + router.middleware.unshift((ctx) => { + ctx.state.env = env; + }); return router.handle(request); }, -} satisfies ExportedHandler; +}; console.log("Cloudflare Worker running with Peko router <3"); diff --git a/wrangler.toml b/wrangler.toml index e5f6a44a..18417f9a 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,4 +1,11 @@ name = "peko" main = "scripts/wrangler/main.ts" node_compat = true -compatibility_date = "2024-02-23" \ No newline at end of file +compatibility_date = "2024-02-23" + +[vars] +ENVIRONMENT = 'production' + +[env.dev.vars] +ENVIRONMENT = 'dev' +