summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/src/runtime.ts
diff options
context:
space:
mode:
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'
+ );
+ }
+}