diff --git a/.changeset/sharp-moles-confess.md b/.changeset/sharp-moles-confess.md new file mode 100644 index 000000000000..03db4840ac63 --- /dev/null +++ b/.changeset/sharp-moles-confess.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-cloudflare': patch +--- + +Add `context` to `event.platform` object diff --git a/packages/adapter-cloudflare/README.md b/packages/adapter-cloudflare/README.md index 769ca13c6799..78038be7cf34 100644 --- a/packages/adapter-cloudflare/README.md +++ b/packages/adapter-cloudflare/README.md @@ -53,7 +53,7 @@ When configuring your project settings, you must use the following settings: ## Environment variables -The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object, containing KV namespaces etc, is passed to SvelteKit via the `platform` property, meaning you can access it in hooks and endpoints: +The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object, containing KV namespaces etc, is passed to SvelteKit via the `platform` property along with `context`, meaning you can access it in hooks and endpoints: ```diff // src/app.d.ts @@ -64,6 +64,9 @@ declare namespace App { + env: { + COUNTER: DurableObjectNamespace; + }; ++ context: { ++ waitUntil(promise: Promise): void; ++ } + } interface Session {} diff --git a/packages/adapter-cloudflare/files/worker.js b/packages/adapter-cloudflare/files/worker.js index 661cf2c3e895..fd256f13b1dd 100644 --- a/packages/adapter-cloudflare/files/worker.js +++ b/packages/adapter-cloudflare/files/worker.js @@ -9,8 +9,9 @@ export default { /** * @param {Request} req * @param {any} env + * @param {any} context */ - async fetch(req, env) { + async fetch(req, env, context) { const url = new URL(req.url); // static assets @@ -49,7 +50,7 @@ export default { // dynamically-generated pages try { - return await app.render(req, { platform: { env } }); + return await app.render(req, { platform: { env, context } }); } catch (e) { return new Response('Error rendering route: ' + (e.message || e.toString()), { status: 500 }); }