From e221a636d5f0f962d4d40028127c8e4599a54427 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Wed, 12 Feb 2025 20:39:09 +0000 Subject: [PATCH 1/2] add callout about `getCloudflareContext` in "async mode" --- pages/cloudflare/bindings.mdx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pages/cloudflare/bindings.mdx b/pages/cloudflare/bindings.mdx index 48dbbfe..923a0b3 100644 --- a/pages/cloudflare/bindings.mdx +++ b/pages/cloudflare/bindings.mdx @@ -27,6 +27,18 @@ export async function GET(request) { } ``` + + `getCloudflareContext` can only be used in SSG routes in "async mode" (where the function's returned value is wrapped + in a promise), to run the function in such a way simply provide an options argument with the `async` flag set to `true`: + ```js + const context = await getCloudflareContext({ async: true }); + ``` + + **WARNING**: During SSG caution is advised since secrets (stored in `.dev.vars` files) and local development + values from bindings (like values saved in a local KV) will be used for the pages static generation. + + + #### How to add bindings to your Worker Add bindings to your Worker by adding them to your [wrangler configuration file](https://developers.cloudflare.com/workers/wrangler/configuration/). From 409eb974cb71fef54eb20fb7760d8d1e6ae71926 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Wed, 12 Feb 2025 20:58:55 +0000 Subject: [PATCH 2/2] Update pages/cloudflare/bindings.mdx Co-authored-by: Victor Berchet --- pages/cloudflare/bindings.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pages/cloudflare/bindings.mdx b/pages/cloudflare/bindings.mdx index 923a0b3..b13fbcf 100644 --- a/pages/cloudflare/bindings.mdx +++ b/pages/cloudflare/bindings.mdx @@ -28,8 +28,7 @@ export async function GET(request) { ``` - `getCloudflareContext` can only be used in SSG routes in "async mode" (where the function's returned value is wrapped - in a promise), to run the function in such a way simply provide an options argument with the `async` flag set to `true`: + `getCloudflareContext` can only be used in SSG routes in "async mode" (making it return a promise), to run the function in such a way simply provide an options argument with `async` set to `true`: ```js const context = await getCloudflareContext({ async: true }); ```