Skip to content

Commit 63d7e4e

Browse files
chore: fix broken env variables in sample worker (#20022)
The current worker example, as copy/pasted would never work at runtime as the environment variable values are not in scope and do not align with the current docs https://developers.cloudflare.com/workers/configuration/environment-variables/#add-environment-variables-via-wrangler
1 parent c349263 commit 63d7e4e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/content/docs/cloudflare-one/identity/authorization-cookie/cors.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Open `/src/index.js` and delete the existing code and paste in the following exa
176176
const originalAPIHostname = "api.mysite.com";
177177

178178
export default {
179-
async fetch(request) {
179+
async fetch(request, env) {
180180
// Change just the host. If the request comes in on example.com/api/name, the new URL is api.mysite.com/api/name
181181
const url = new URL(request.url);
182182
url.hostname = originalAPIHostname;
@@ -191,8 +191,8 @@ export default {
191191
// since once a Request has been constructed, its URL is immutable.
192192
const newRequest = new Request(url.toString(), request);
193193

194-
newRequest.headers.set("cf-access-client-id", CF_ACCESS_CLIENT_ID);
195-
newRequest.headers.set("cf-access-client-secret", CF_ACCESS_CLIENT_SECRET);
194+
newRequest.headers.set("cf-access-client-id", env.CF_ACCESS_CLIENT_ID);
195+
newRequest.headers.set("cf-access-client-secret", env.CF_ACCESS_CLIENT_SECRET);
196196
try {
197197
const response = await fetch(newRequest);
198198

0 commit comments

Comments
 (0)