Skip to content

Commit d52da17

Browse files
committed
Convert all existing config
1 parent c3cdd6f commit d52da17

File tree

122 files changed

+2594
-1781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2594
-1781
lines changed

src/components/WranglerConfig.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ if (language === "toml") {
4545
---
4646

4747
<Tabs syncKey="wranglerConfig">
48-
<TabItem label="wrangler.json" icon="seti:json">
49-
<Code lang="jsonc" code={json} />
50-
</TabItem>
5148
<TabItem label="wrangler.toml" icon="setting">
5249
<Code lang="toml" code={toml} />
5350
</TabItem>
51+
<TabItem label="wrangler.json" icon="seti:json">
52+
<Code lang="jsonc" code={json} />
53+
</TabItem>
5454
</Tabs>

src/content/docs/analytics/analytics-engine/get-started.mdx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,26 @@ sidebar:
66
head:
77
- tag: title
88
content: Get started with Workers Analytics Engine
9-
109
---
1110

12-
import { DirectoryListing } from "~/components"
11+
import { DirectoryListing } from "~/components";
1312

1413
## 1. Name your dataset and add it to your Worker
1514

1615
Add the following to your `wrangler.toml` file to create a [binding](/workers/runtime-apis/bindings/) to a Workers Analytics Engine dataset. A dataset is like a table in SQL: the rows and columns should have consistent meaning.
1716

17+
import { WranglerConfig } from "~/components";
18+
19+
<WranglerConfig>
20+
1821
```toml
1922
[[analytics_engine_datasets]]
2023
binding = "<BINDING_NAME>"
2124
dataset = "<DATASET_NAME>"
2225
```
2326

27+
</WranglerConfig>
28+
2429
## 2. Write data points from your Worker
2530

2631
You can write data points to your Worker by calling the `writeDataPoint()` method that is exposed on the binding that you just created.
@@ -38,14 +43,14 @@ async fetch(request, env) {
3843

3944
:::note
4045

41-
You do not need to await `writeDataPoint()` — it will return immediately, and the Workers runtime handles writing your data in the background.
46+
You do not need to await `writeDataPoint()` — it will return immediately, and the Workers runtime handles writing your data in the background.
4247
:::
4348

4449
A data point is a structured event that consists of:
4550

46-
* **Blobs** (strings) — The dimensions used for grouping and filtering. Sometimes called labels in other metrics systems.
47-
* **Doubles** (numbers) — The numeric values that you want to record in your data point.
48-
* **Indexes** — (strings) — Used as a [sampling](/analytics/analytics-engine/sql-api/#sampling) key.
51+
- **Blobs** (strings) — The dimensions used for grouping and filtering. Sometimes called labels in other metrics systems.
52+
- **Doubles** (numbers) — The numeric values that you want to record in your data point.
53+
- **Indexes** — (strings) — Used as a [sampling](/analytics/analytics-engine/sql-api/#sampling) key.
4954

5055
In the example above, suppose you are collecting air quality samples. Each data point written represents a reading from your weather sensor. The blobs define city, state, and sensor model — the dimensions you want to be able to filter queries on later. The doubles define the numeric temperature and air pressure readings. And the index is the ID of your customer. You may want to include [context about the incoming request](/workers/runtime-apis/request/), such as geolocation, to add additional data to your datapoint.
5156

@@ -55,8 +60,8 @@ Currently, the `writeDataPoint()` API accepts ordered arrays of values. This mea
5560

5661
You can query the data you have written in two ways:
5762

58-
* [**SQL API**](/analytics/analytics-engine/sql-api) — Best for writing your own queries and integrating with external tools like Grafana.
59-
* [**GraphQL API**](/analytics/graphql-api/) — This is the same API that powers the Cloudflare dashboard.
63+
- [**SQL API**](/analytics/analytics-engine/sql-api) — Best for writing your own queries and integrating with external tools like Grafana.
64+
- [**GraphQL API**](/analytics/graphql-api/) — This is the same API that powers the Cloudflare dashboard.
6065

6166
For the purpose of this example, we will use the SQL API.
6267

@@ -81,7 +86,7 @@ LIMIT 10
8186

8287
:::note
8388

84-
We are using a custom averaging function to take [sampling](/analytics/analytics-engine/sql-api/#sampling) into account.
89+
We are using a custom averaging function to take [sampling](/analytics/analytics-engine/sql-api/#sampling) into account.
8590
:::
8691

8792
You can run this query by making an HTTP request to the SQL API:
@@ -117,6 +122,4 @@ Refer to [Querying Workers Analytics Engine from Grafana](/analytics/analytics-e
117122

118123
## Further reading
119124

120-
<DirectoryListing
121-
folder="analytics/analytics-engine"
122-
/>
125+
<DirectoryListing folder="analytics/analytics-engine" />

src/content/docs/analytics/analytics-engine/worker-querying.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ First the environment variables are set up with the account ID and API token.
4848

4949
The account ID is set in `wrangler.toml`:
5050

51+
import { WranglerConfig } from "~/components";
52+
53+
<WranglerConfig>
54+
5155
```toml
5256
[vars]
5357
ACCOUNT_ID = "<account_id>"
5458
```
5559

60+
</WranglerConfig>
61+
5662
The API_TOKEN can be set as a secret, using the wrangler command line tool, by running the following and entering your token string:
5763

5864
```sh

src/content/docs/browser-rendering/get-started/browser-rendering-with-DO.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ Configure your `browser-worker` project's [`wrangler.toml`](/workers/wrangler/co
7575

7676
Update your `wrangler.toml` configuration file with the Browser Rendering API binding, the R2 bucket you created and a Durable Object:
7777

78+
import { WranglerConfig } from "~/components";
79+
80+
<WranglerConfig>
81+
7882
```toml
7983
name = "rendering-api-demo"
8084
main = "src/index.js"
@@ -103,6 +107,8 @@ new_classes = ["Browser"] # Array of new classes
103107

104108
```
105109

110+
</WranglerConfig>
111+
106112
## 6. Code
107113

108114
The code below uses Durable Object to instantiate a browser using Puppeteer. It then opens a series of web pages with different resolutions, takes a screenshot of each, and uploads it to R2.

src/content/docs/browser-rendering/get-started/screenshots.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Configure your `browser-worker` project's [`wrangler.toml`](/workers/wrangler/co
6262

6363
Update your `wrangler.toml` configuration file with the Browser Rendering API binding and the KV namespaces you created:
6464

65+
import { WranglerConfig } from "~/components";
66+
67+
<WranglerConfig>
68+
6569
```toml
6670
name = "browser-worker"
6771
main = "src/index.js"
@@ -74,6 +78,8 @@ kv_namespaces = [
7478
]
7579
```
7680

81+
</WranglerConfig>
82+
7783
## 5. Code
7884

7985
<Tabs> <TabItem label="JavaScript" icon="seti:javascript">

src/content/docs/browser-rendering/platform/wrangler.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ To deploy a Browser Rendering Worker, you must declare a [browser binding](/work
2424
If you are using [Puppeteer](/browser-rendering/platform/puppeteer/) in your Worker code, then you also need to add "nodejs_compat_v2" to the compatibility_flags in your Worker's `wrangler.toml` configuration. More information [here](/workers/runtime-apis/nodejs/#enable-nodejs-with-workers), including for [pages functions](/workers/runtime-apis/nodejs/#enable-nodejs-with-pages-functions).
2525
:::
2626

27+
import { WranglerConfig } from "~/components";
28+
29+
<WranglerConfig>
30+
2731
```toml
2832
# Top-level configuration
2933
name = "browser-rendering"
@@ -34,6 +38,8 @@ compatibility_flags = ["nodejs_compat_v2"]
3438
browser = { binding = "MYBROWSER" }
3539
```
3640

41+
</WranglerConfig>
42+
3743
After the binding is declared, access the DevTools endpoint using `env.MYBROWSER` in your Worker code:
3844

3945
```javascript
Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
pcx_content_type: concept
33
title: Outbound Workers
4-
54
---
65

76
Outbound Workers sit between your customer’s Workers and the public Internet. They give you visibility into all outgoing `fetch()` requests from user Workers.
@@ -12,9 +11,9 @@ Outbound Workers sit between your customer’s Workers and the public Internet.
1211

1312
Outbound Workers can be used to:
1413

15-
* Log all subrequests to identify malicious domains or usage patterns.
16-
* Create, allow, or block lists for hostnames requested by user Workers.
17-
* Configure authentication to your APIs behind the scenes (without end developers needing to set credentials).
14+
- Log all subrequests to identify malicious domains or usage patterns.
15+
- Create, allow, or block lists for hostnames requested by user Workers.
16+
- Configure authentication to your APIs behind the scenes (without end developers needing to set credentials).
1817

1918
## Use Outbound Workers
2019

@@ -25,47 +24,53 @@ To use Outbound Workers:
2524

2625
Make sure that you have `[email protected]` or later [installed](/workers/wrangler/install-and-update/).
2726

27+
import { WranglerConfig } from "~/components";
28+
29+
<WranglerConfig>
30+
2831
```toml
2932
[[dispatch_namespaces]]
3033
binding = "dispatcher"
3134
namespace = "<NAMESPACE_NAME>"
3235
outbound = {service = "<SERVICE_NAME>", parameters = ["params_object"]}
3336
```
3437

38+
</WranglerConfig>
39+
3540
3. Edit your dynamic dispatch Worker to call the Outbound Worker and declare variables to pass on `dispatcher.get()`.
3641

3742
```js
3843
export default {
3944
async fetch(request, env) {
40-
try {
41-
42-
// parse the URL, read the subdomain
43-
let workerName = new URL(request.url).host.split('.')[0];
44-
45-
let context_from_dispatcher = {
46-
'customer_name': workerName,
47-
'url': request.url,
48-
}
49-
50-
let userWorker = env.dispatcher.get(
51-
workerName,
52-
{},
53-
{// outbound arguments. object name must match parameters in the binding
54-
outbound: {
55-
params_object: context_from_dispatcher,
56-
}
57-
}
58-
);
59-
return await userWorker.fetch(request);
60-
} catch (e) {
61-
if (e.message.startsWith('Worker not found')) {
62-
// we tried to get a worker that doesn't exist in our dispatch namespace
63-
return new Response('', { status: 404 });
45+
try {
46+
// parse the URL, read the subdomain
47+
let workerName = new URL(request.url).host.split(".")[0];
48+
49+
let context_from_dispatcher = {
50+
customer_name: workerName,
51+
url: request.url,
52+
};
53+
54+
let userWorker = env.dispatcher.get(
55+
workerName,
56+
{},
57+
{
58+
// outbound arguments. object name must match parameters in the binding
59+
outbound: {
60+
params_object: context_from_dispatcher,
61+
},
62+
},
63+
);
64+
return await userWorker.fetch(request);
65+
} catch (e) {
66+
if (e.message.startsWith("Worker not found")) {
67+
// we tried to get a worker that doesn't exist in our dispatch namespace
68+
return new Response("", { status: 404 });
69+
}
70+
return new Response(e.message, { status: 500 });
6471
}
65-
return new Response(e.message, { status: 500 });
66-
}
67-
}
68-
}
72+
},
73+
};
6974
```
7075

7176
4. The Outbound Worker will now be invoked on any `fetch()` requests from a user Worker. The user Worker will trigger a [FetchEvent](/workers/runtime-apis/handlers/fetch/) on the Outbound Worker. The variables declared in the binding can be accessed in the Outbound Worker through `env.<VAR_NAME>`.
@@ -74,47 +79,44 @@ The following is an example of an Outbound Worker that logs the fetch request fr
7479

7580
```js
7681
export default {
77-
// this event is fired when the dispatched Workers make a subrequest
78-
async fetch(request, env, ctx) {
79-
// env contains the values we set in `dispatcher.get()`
80-
const customer_name = env.customer_name;
81-
const original_url = env.url;
82-
83-
// log the request
84-
ctx.waitUntil(fetch(
85-
'https://logs.example.com',
86-
{
87-
method: 'POST',
88-
body: JSON.stringify({
89-
customer_name,
90-
original_url,
91-
}),
92-
},
93-
));
94-
95-
const url = new URL(original_url);
96-
if (url.host === 'api.example.com') {
97-
// pre-auth requests to our API
98-
const jwt = make_jwt_for_customer(customer_name);
99-
100-
let headers = new Headers(request.headers);
101-
headers.set('Authorization', `Bearer ${jwt}`);
102-
103-
// clone the request to set new headers using existing body
104-
let new_request = new Request(request, {headers});
105-
106-
return fetch(new_request)
107-
}
108-
109-
return fetch(request)
110-
}
82+
// this event is fired when the dispatched Workers make a subrequest
83+
async fetch(request, env, ctx) {
84+
// env contains the values we set in `dispatcher.get()`
85+
const customer_name = env.customer_name;
86+
const original_url = env.url;
87+
88+
// log the request
89+
ctx.waitUntil(
90+
fetch("https://logs.example.com", {
91+
method: "POST",
92+
body: JSON.stringify({
93+
customer_name,
94+
original_url,
95+
}),
96+
}),
97+
);
98+
99+
const url = new URL(original_url);
100+
if (url.host === "api.example.com") {
101+
// pre-auth requests to our API
102+
const jwt = make_jwt_for_customer(customer_name);
103+
104+
let headers = new Headers(request.headers);
105+
headers.set("Authorization", `Bearer ${jwt}`);
106+
107+
// clone the request to set new headers using existing body
108+
let new_request = new Request(request, { headers });
109+
110+
return fetch(new_request);
111+
}
112+
113+
return fetch(request);
114+
},
111115
};
112116
```
113117

114118
:::note
115119

116-
117120
Outbound Workers do not intercept fetch requests made from [Durable Objects](/durable-objects/) or [mTLS certificate bindings](/workers/runtime-apis/bindings/mtls/).
118121

119-
120122
:::

src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,18 @@ cd my-dispatcher
9999

100100
Open the `wrangler.toml` file in your project directory, and add the dispatch namespace binding:
101101

102+
import { WranglerConfig } from "~/components";
103+
104+
<WranglerConfig>
105+
102106
```toml
103107
[[dispatch_namespaces]]
104108
binding = "DISPATCHER"
105109
namespace = "testing"
106110
```
107111

112+
</WranglerConfig>
113+
108114
Add the following to the index.js file:
109115

110116
```js

0 commit comments

Comments
 (0)