-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <>
- Loading branch information
1 parent
b98672f
commit 9cd362f
Showing
5 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters