Skip to content

Commit 731b03c

Browse files
teemingcbenmccanndario-piotrowicz
authored
chore: docs and changeset for #11732 (#11974)
* add changeset * documentation * Update documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md Co-authored-by: Ben McCann <[email protected]> * Update documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md Co-authored-by: Dario Piotrowicz <[email protected]> --------- Co-authored-by: Ben McCann <[email protected]> Co-authored-by: Dario Piotrowicz <[email protected]>
1 parent 4447269 commit 731b03c

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

.changeset/lucky-chefs-sleep.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@sveltejs/adapter-cloudflare-workers": minor
3+
"@sveltejs/adapter-cloudflare": minor
4+
---
5+
6+
feat: emulate Cloudflare Workers bindings and incoming request properties in `event.platform` for `dev` and `preview`

documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Cloudflare Pages
44

55
To deploy to [Cloudflare Pages](https://developers.cloudflare.com/pages/), use [`adapter-cloudflare`](https://github.com/sveltejs/kit/tree/main/packages/adapter-cloudflare).
66

7-
This adapter will be installed by default when you use [`adapter-auto`](adapter-auto). If you plan on staying with Cloudflare Pages you can switch from [`adapter-auto`](adapter-auto) to using this adapter directly so that type declarations will be automatically applied and you can set Cloudflare-specific options.
7+
This adapter will be installed by default when you use [`adapter-auto`](adapter-auto). If you plan on staying with Cloudflare Pages, you can switch from [`adapter-auto`](adapter-auto) to using this adapter directly so that values specific to Cloudflare Workers are emulated during local development, type declarations are automatically applied, and the ability to set Cloudflare-specific options is provided.
88

99
## Comparisons
1010

@@ -57,9 +57,9 @@ When configuring your project settings, you must use the following settings:
5757
- **Build command**`npm run build` or `vite build`
5858
- **Build output directory**`.svelte-kit/cloudflare`
5959

60-
## Bindings
60+
## Runtime APIs
6161

62-
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/pages/platform/functions/bindings/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with `context` and `caches`, meaning that you can access it in hooks and endpoints:
62+
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/pages/platform/functions/bindings/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with [`context`](https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/#contextwaituntil), [`caches`](https://developers.cloudflare.com/workers/runtime-apis/cache/), and [`cf`](https://developers.cloudflare.com/workers/runtime-apis/request/#the-cf-property-requestinitcfproperties), meaning that you can access it in hooks and endpoints:
6363

6464
```js
6565
// @errors: 7031
@@ -70,7 +70,7 @@ export async function POST({ request, platform }) {
7070

7171
> SvelteKit's built-in `$env` module should be preferred for environment variables.
7272
73-
To make these types available to your app, reference them in your `src/app.d.ts`:
73+
To include type declarations for your bindings, reference them in your `src/app.d.ts`:
7474

7575
```diff
7676
/// file: src/app.d.ts
@@ -90,7 +90,9 @@ export {};
9090

9191
### Testing Locally
9292

93-
`platform.env` is only available in the final build and not in dev mode. For testing the build, you can use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler) **version 3**. Once you have built your site, run `wrangler pages dev .svelte-kit/cloudflare`. Ensure you have your [bindings](https://developers.cloudflare.com/workers/wrangler/configuration/#bindings) in your `wrangler.toml`.
93+
Cloudflare Workers specific values in the `platform` property are emulated during dev and preview modes. The [bindings](https://developers.cloudflare.com/workers/wrangler/configuration/#bindings) in your `wrangler.toml` will be used to populate `platform.env` during local development.
94+
95+
For testing the build, you should use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler) **version 3**. Once you have built your site, run `wrangler pages dev .svelte-kit/cloudflare`.
9496

9597
## Notes
9698

documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ If you would like to enable [Node.js compatibility](https://developers.cloudflar
8484
compatibility_flags = [ "nodejs_compat" ]
8585
```
8686

87-
## Bindings
87+
## Runtime APIs
8888

89-
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/workers/platform/environment-variables/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with `context` and `caches`, meaning that you can access it in hooks and endpoints:
89+
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/pages/platform/functions/bindings/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with [`context`](https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/#contextwaituntil), [`caches`](https://developers.cloudflare.com/workers/runtime-apis/cache/), and [`cf`](https://developers.cloudflare.com/workers/runtime-apis/request/#the-cf-property-requestinitcfproperties), meaning that you can access it in hooks and endpoints:
9090

9191
```js
9292
// @errors: 7031
@@ -97,7 +97,7 @@ export async function POST({ request, platform }) {
9797

9898
> SvelteKit's built-in `$env` module should be preferred for environment variables.
9999
100-
To make these types available to your app, reference them in your `src/app.d.ts`:
100+
To include type declarations for your bindings, reference them in your `src/app.d.ts`:
101101

102102
```diff
103103
/// file: src/app.d.ts
@@ -117,7 +117,9 @@ export {};
117117

118118
### Testing Locally
119119

120-
`platform.env` is only available in the final build and not in dev mode. For testing the build, you can use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler). Once you have built your site, run `wrangler dev`. Ensure you have your [bindings](https://developers.cloudflare.com/workers/wrangler/configuration/#bindings) in your `wrangler.toml`. Wrangler version 3 is recommended.
120+
Cloudflare Workers specific values in the `platform` property are emulated during dev and preview modes. The [bindings](https://developers.cloudflare.com/workers/wrangler/configuration/#bindings) in your `wrangler.toml` will be used to populate `platform.env` during local development.
121+
122+
For testing the build, you should use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler) **version 3**. Once you have built your site, run `wrangler dev`.
121123

122124
## Troubleshooting
123125

0 commit comments

Comments
 (0)