Skip to content

Commit

Permalink
adds cloudflare cf object to platform property
Browse files Browse the repository at this point in the history
this has been done for the pages package but not for workers.
see #9978
  • Loading branch information
Philipp Viereck committed Oct 15, 2023
1 parent fd6eb9b commit 115c8bd
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 115c8bd

Please sign in to comment.