Skip to content

Commit 694500c

Browse files
committed
Adding warning note to use request.clone() in all
places where the code uses request.formData().
1 parent 5823161 commit 694500c

File tree

13 files changed

+49
-11
lines changed

13 files changed

+49
-11
lines changed

src/content/docs/images/tutorials/optimize-user-uploaded-image.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66
order: 1
77
---
88

9-
import { WranglerConfig } from "~/components"
9+
import { WranglerConfig, Render } from "~/components"
1010

1111

1212
In this guide, you will build an app that accepts image uploads, overlays the image with a visual watermark, then stores the transformed image in your R2 bucket.
@@ -142,6 +142,8 @@ export default {
142142
};
143143
```
144144

145+
<Render file="request-dot-clone-warning" product="workers" />
146+
145147
## 4: Transform the image
146148

147149
For every uploaded image, you want to perform the following actions:

src/content/docs/pages/functions/plugins/hcaptcha.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ sidebar:
55
order: 1
66
---
77

8+
import { Render } from "~/components"
9+
810
The hCaptcha Pages Plugin validates hCaptcha tokens.
911

1012
## Installation
@@ -35,6 +37,8 @@ export const onRequestPost: PagesFunction[] = [
3537
];
3638
```
3739

40+
<Render file="request-dot-clone-warning" product="workers" />
41+
3842
This Plugin only exposes a single route. It will be available wherever it is mounted. In the above example, because it is mounted in `functions/register.ts`, it will validate requests to `/register`. The Plugin is mounted with a single object parameter with the following properties.
3943

4044
[`secret`](https://dashboard.hcaptcha.com/settings) (mandatory) and [`sitekey`](https://dashboard.hcaptcha.com/sites) (optional) can both be found in your hCaptcha dashboard.

src/content/docs/pages/functions/plugins/index.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66

77
---
88

9-
import { DirectoryListing } from "~/components"
9+
import { DirectoryListing, Render } from "~/components"
1010

1111
Cloudflare maintains a number of official Pages Plugins for you to use in your Pages projects:
1212

@@ -136,6 +136,8 @@ export const onRequestPost = async (context) => {
136136
}
137137
```
138138

139+
<Render file="request-dot-clone-warning" product="workers" />
140+
139141
### 2. Type your Pages Plugin
140142

141143
To create a good developer experience, you should consider adding TypeScript typings to your Plugin. This allows developers to use their IDE features for autocompletion, and also ensure that they include all the parameters you are expecting.

src/content/docs/pages/functions/plugins/turnstile.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ sidebar:
55
order: 1
66
---
77

8+
import { Render } from "~/components"
9+
810
[Turnstile](/turnstile/) is Cloudflare's smart CAPTCHA alternative.
911

1012
The Turnstile Pages Plugin validates Cloudflare Turnstile tokens.
@@ -45,6 +47,8 @@ export const onRequestPost = [
4547
];
4648
```
4749

50+
<Render file="request-dot-clone-warning" product="workers" />
51+
4852
This Plugin only exposes a single route to verify an incoming Turnstile response in a `POST` as the `cf-turnstile-response` parameter. It will be available wherever it is mounted. In the example above, it is mounted in `functions/register.ts`. As a result, it will validate requests to `/register`.
4953

5054
## Properties

src/content/docs/pages/how-to/refactor-a-worker-to-pages-functions.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pcx_content_type: how-to
33
title: Refactor a Worker to a Pages Function
44
---
55

6+
import { Render } from "~/components"
7+
68
In this guide, you will learn how to refactor a Worker made to intake form submissions to a Pages Function that can be hosted on your Cloudflare Pages application. [Pages Functions](/pages/functions/) is a serverless function that lives within the same project directory as your application and is deployed with Cloudflare Pages. It enables you to run server-side code that adds dynamic functionality without running a dedicated server. You may want to refactor a Worker to a Pages Function for one of these reasons:
79

810
1. If you manage a serverless function that your Pages application depends on and wish to ship the logic without managing a Worker as a separate service.
@@ -101,6 +103,8 @@ const HandleAirtableData = (body, env) => {
101103
};
102104
```
103105

106+
<Render file="request-dot-clone-warning" product="workers" />
107+
104108
### Refactor your Worker
105109

106110
To refactor the above Worker, go to your Pages project directory and create a `/functions` folder. In `/functions`, create a `form.js` file. This file will handle form submissions.

src/content/docs/pages/tutorials/forms/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ languages:
99
- JavaScript
1010
---
1111

12+
import { Render } from "~/components"
13+
1214
In this tutorial, you will create a simple `<form>` using plain HTML and CSS and deploy it to Cloudflare Pages. While doing so, you will learn about some of the HTML form attributes and how to collect submitted data within a Worker.
1315

1416
:::note[MDN Introductory Series]
@@ -271,6 +273,8 @@ With this handler in place, the example is now fully functional. When a submissi
271273

272274
However, if you want to reply with a JSON object instead of the key-value pairs (an Array of Arrays), then you must do so manually. Recently, JavaScript added the [`Object.fromEntries`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries) utility. This works well in some cases; however, the example `<form>` includes a `movies` checklist that allows for multiple values. If using `Object.fromEntries`, the generated object would only keep one of the `movies` values, discarding the rest. To avoid this, you must write your own `FormData` to `Object` utility instead:
273275

276+
<Render file="request-dot-clone-warning" product="workers" />
277+
274278
```js
275279
/**
276280
* POST /api/submit

src/content/docs/r2/api/workers/workers-api-usage.mdx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,7 @@ export default {
129129
};
130130
```
131131

132-
:::caution[Prevent potential errors when accessing request.body]
133-
134-
The body of a [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) can only be accessed once. If you previously used `request.formData()` in the same request, you may encounter a TypeError when attempting to access `request.body`.<br/><br/>
135-
To avoid errors, create a clone of the Request object with `request.clone()` for each subsequent attempt to access a Request's body.
136-
Keep in mind that Workers have a [memory limit of 128MB per Worker](https://developers.cloudflare.com/workers/platform/limits#worker-limits) and loading particularly large files into a Worker's memory multiple times may reach this limit. To ensure memory usage does not reach this limit, consider using [Streams](https://developers.cloudflare.com/workers/runtime-apis/streams/).
137-
138-
:::
132+
<Render file="request-dot-clone-warning" product="workers" />
139133

140134
## 5. Bucket access and privacy
141135

src/content/docs/r2/tutorials/summarize-pdf.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ The above code does the following:
278278

279279
Since the Worker code is written in TypeScript, you should run the following command to add the necessary type definitions. While this is not required, it will help you avoid errors.
280280

281+
<Render file="request-dot-clone-warning" product="workers" />
282+
281283
```sh
282284
npm run cf-typegen
283285
```

src/content/docs/turnstile/tutorials/implicit-vs-explicit-rendering.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ sidebar:
1212

1313
---
1414

15+
import { Render } from "~/components";
16+
1517
This tutorial will explore the two primary methods of implementing Turnstile to your website via **implicit or explicit rendering** using a detailed explanation, a step by step implementation guide, and examples on how to help you protect your web application security while maintaining a good user experience.
1618

1719
## Before you begin
@@ -235,6 +237,8 @@ export default {
235237
};
236238
```
237239
240+
<Render file="request-dot-clone-warning" product="workers" />
241+
238242
## Choose between implicit and explicit rendering
239243
240244
Choosing the appropriate rendering method for Turnstile is important and effectively helps you to add it to your website while ensuring optimal performance and user experience. Both implicit and explicit rendering have their own advantages and are suited to different types of web applications. Refer to the table below that highlights the ideal use case for each of these rendering methods:

src/content/docs/workers/examples/read-post.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ description: Serve an HTML form, then read POST requests. Use also to read JSON
1717
or POST data from an incoming request.
1818
---
1919

20-
import { TabItem, Tabs } from "~/components";
20+
import { TabItem, Tabs, Render } from "~/components";
2121

2222
<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
2323

@@ -285,3 +285,5 @@ export default app;
285285
```
286286

287287
</TabItem> </Tabs>
288+
289+
<Render file="request-dot-clone-warning" product="workers" />

0 commit comments

Comments
 (0)