Skip to content

Commit

Permalink
spread env into process.env
Browse files Browse the repository at this point in the history
in the _worker.js template take the provided env and
spread its values into the global process.env so that
bindings can be accessed in the Next.js application
  • Loading branch information
dario-piotrowicz committed Jan 25, 2023
1 parent c024bc7 commit 9ef93ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-coins-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/next-on-pages": minor
---

Environment variables and bindings are now available on `process.env` from within your SSR'd pages/API handlers!
2 changes: 2 additions & 0 deletions templates/_worker.js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ declare const __MIDDLEWARE__: EdgeFunctions;

export default {
async fetch(request, env, context) {
globalThis.process.env = { ...globalThis.process.env, ...env };

const { pathname } = new URL(request.url);
const routes = routesMatcher({ request }, __CONFIG__.routes);

Expand Down

0 comments on commit 9ef93ff

Please sign in to comment.