summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/src/runtime.ts
diff options
context:
space:
mode:
authorGravatar Daniel <daniel.freese@gmail.com> 2022-10-26 15:46:25 +0200
committerGravatar GitHub <noreply@github.com> 2022-10-26 09:46:25 -0400
commitd151d9f3f29c0a57c59b8029a18717808ccc7f8f (patch)
treed6ddc610bf46bbfe50eeb1bf3fe3362529d82f30 /packages/integrations/cloudflare/src/runtime.ts
parent4efbfdd78d239f708a76eac38c2e971fc956a54e (diff)
downloadastro-d151d9f3f29c0a57c59b8029a18717808ccc7f8f.tar.gz
astro-d151d9f3f29c0a57c59b8029a18717808ccc7f8f.tar.zst
astro-d151d9f3f29c0a57c59b8029a18717808ccc7f8f.zip
enable access to cloudflare runtime (#5103)
* enable access to cloudflare runtime * added get runtime api added context to the runtime in "advanced" mode * added typings and adjusted some return vars * added default types * added usage description to changeset and readme Co-authored-by: AirBorne04 <unknown> Co-authored-by: AirBorne04 <>
Diffstat (limited to 'packages/integrations/cloudflare/src/runtime.ts')
-rw-r--r--packages/integrations/cloudflare/src/runtime.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/integrations/cloudflare/src/runtime.ts b/packages/integrations/cloudflare/src/runtime.ts
new file mode 100644
index 000000000..ddf372cb4
--- /dev/null
+++ b/packages/integrations/cloudflare/src/runtime.ts
@@ -0,0 +1,28 @@
+export type WorkerRuntime<T = unknown> = {
+ name: 'cloudflare';
+ env: T;
+ waitUntil(promise: Promise<any>): void;
+ passThroughOnException(): void;
+};
+
+export type PagesRuntime<T = unknown, U = unknown> = {
+ name: 'cloudflare';
+ env: T;
+ functionPath: string;
+ params: Record<string, string>;
+ data: U;
+ waitUntil(promise: Promise<any>): void;
+ next(request: Request): void;
+};
+
+export function getRuntime<T = unknown, U = unknown>(
+ request: Request
+): WorkerRuntime<T> | PagesRuntime<T, U> {
+ if (!!request) {
+ return Reflect.get(request, Symbol.for('runtime'));
+ } else {
+ throw new Error(
+ 'To retrieve the current cloudflare runtime you need to pass in the Astro request object'
+ );
+ }
+}