Skip to content

Commit

Permalink
feat: add cloudflare cf object to platform in `adapter-cloudflare-w…
Browse files Browse the repository at this point in the history
…orkers` (#10873)
  • Loading branch information
philippviereck authored Oct 25, 2023
1 parent 6e967ff commit 799b9e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-pigs-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-cloudflare-workers': minor
---

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

declare global {
namespace App {
Expand All @@ -7,6 +7,7 @@ declare global {
waitUntil(promise: Promise<any>): void;
};
caches: CacheStorage;
cf?: IncomingRequestCfProperties;
}
}
}
4 changes: 3 additions & 1 deletion packages/adapter-cloudflare-workers/files/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export default {
env,
context,
// @ts-expect-error lib.dom is interfering with workers-types
caches
caches,
// @ts-expect-error req is actually a Cloudflare request not a standard request
cf: req.cf
},
getClientAddress() {
return req.headers.get('cf-connecting-ip');
Expand Down

0 comments on commit 799b9e7

Please sign in to comment.