From 1bdc37d77d6219439e144fa5154c9fe0b3ecb061 Mon Sep 17 00:00:00 2001 From: venashial Date: Thu, 26 May 2022 07:16:02 +0000 Subject: [PATCH 1/2] Expose `caches` to Cloudflare adapter --- packages/adapter-cloudflare/README.md | 5 +++-- packages/adapter-cloudflare/src/worker.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/adapter-cloudflare/README.md b/packages/adapter-cloudflare/README.md index d4243d7ebebd..eb1deb4c433f 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 along with `context`, 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` and `caches`, meaning you can access it in hooks and endpoints: ```diff // src/app.d.ts @@ -66,7 +66,8 @@ declare namespace App { + }; + context: { + waitUntil(promise: Promise): void; -+ } ++ }; ++ caches: CacheStorage & { default: Cache } + } interface Session {} diff --git a/packages/adapter-cloudflare/src/worker.js b/packages/adapter-cloudflare/src/worker.js index 4a53b71ea0ee..1ba1bf8d145a 100644 --- a/packages/adapter-cloudflare/src/worker.js +++ b/packages/adapter-cloudflare/src/worker.js @@ -54,7 +54,7 @@ const worker = { } else { // dynamically-generated pages res = await server.respond(req, { - platform: { env, context }, + platform: { env, context, caches }, getClientAddress() { return req.headers.get('cf-connecting-ip'); } From 5ca08b58963e76fcb5a0dbc83dc2698cd330adf2 Mon Sep 17 00:00:00 2001 From: venashial Date: Thu, 26 May 2022 07:25:20 +0000 Subject: [PATCH 2/2] Add changeset --- .changeset/sixty-bees-explain.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sixty-bees-explain.md diff --git a/.changeset/sixty-bees-explain.md b/.changeset/sixty-bees-explain.md new file mode 100644 index 000000000000..8cc793564c52 --- /dev/null +++ b/.changeset/sixty-bees-explain.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-cloudflare': minor +--- + +Expose Cloudflare Worker Cache API through `caches` in Platform