Skip to content

Commit

Permalink
adds cloudflare cf object to platform property (#9978)
Browse files Browse the repository at this point in the history
* adds cloudflare cf object to platform property

* Update afraid-bikes-count.md

---------

Co-authored-by: Spioune <>
Co-authored-by: Tee Ming <[email protected]>
Spioune and eltigerchino authored May 19, 2023
1 parent 195e9ac commit b5d96cb
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-bikes-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-cloudflare': minor
---

feat: add cloudflare's `request.cf` object to the `event.platform` property
3 changes: 2 additions & 1 deletion packages/adapter-cloudflare/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cache, CacheStorage } from '@cloudflare/workers-types';
import { Cache, CacheStorage, IncomingRequestCfProperties } from '@cloudflare/workers-types';

declare global {
namespace App {
@@ -7,6 +7,7 @@ declare global {
waitUntil(promise: Promise<any>): void;
};
caches?: CacheStorage & { default: Cache };
cf?: IncomingRequestCfProperties;
}
}
}
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/src/worker.js
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ const worker = {
// dynamically-generated pages
res = await server.respond(req, {
// @ts-ignore
platform: { env, context, caches },
platform: { env, context, caches, cf: req.cf },
getClientAddress() {
return req.headers.get('cf-connecting-ip');
}

0 comments on commit b5d96cb

Please sign in to comment.