Skip to content

Commit

Permalink
fix: wrangler env
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Ringrose committed Jul 22, 2024
1 parent 95e6d86 commit 544cf00
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 5 additions & 6 deletions scripts/wrangler/main.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>) {
router.middleware.unshift((ctx) => {
ctx.state.env = env;
});
return router.handle(request);
},
} satisfies ExportedHandler;
};

console.log("Cloudflare Worker running with Peko router <3");
9 changes: 8 additions & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
name = "peko"
main = "scripts/wrangler/main.ts"
node_compat = true
compatibility_date = "2024-02-23"
compatibility_date = "2024-02-23"

[vars]
ENVIRONMENT = 'production'

[env.dev.vars]
ENVIRONMENT = 'dev'

0 comments on commit 544cf00

Please sign in to comment.