Skip to content

Commit

Permalink
added get runtime api
Browse files Browse the repository at this point in the history
added context to the runtime in "advanced" mode
  • Loading branch information
AirBorne04 authored and AirBorne04 committed Oct 21, 2022
1 parent da2a317 commit 34f54ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/integrations/cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@astrojs/cloudflare",
"description": "Deploy your site to cloudflare pages functions",
"description": "Deploy your site to cloudflare workers or cloudflare pages",
"version": "3.1.0",
"type": "module",
"types": "./dist/index.d.ts",
Expand All @@ -19,6 +19,7 @@
"homepage": "https://docs.astro.build/en/guides/integrations-guide/cloudflare/",
"exports": {
".": "./dist/index.js",
"./runtime": "./dist/runtime.js",
"./server.advanced.js": "./dist/server.advanced.js",
"./server.directory.js": "./dist/server.directory.js",
"./package.json": "./package.json"
Expand Down
7 changes: 7 additions & 0 deletions packages/integrations/cloudflare/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

export function getRuntime(request: Request): any {
return Reflect.get(
request,
Symbol.for('runtime')
);
}
5 changes: 3 additions & 2 deletions packages/integrations/cloudflare/src/server.advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ type Env = {
export function createExports(manifest: SSRManifest) {
const app = new App(manifest, false);

const fetch = async (request: Request, env: Env) => {
const fetch = async (request: Request, env: Env, context: any) => {

const { origin, pathname } = new URL(request.url);
env.name = "cloudflare";

Expand All @@ -31,7 +32,7 @@ export function createExports(manifest: SSRManifest) {
Reflect.set(
request,
Symbol.for('runtime'),
env
{ env, ...context }
);
let response = await app.render(request, routeData);

Expand Down

0 comments on commit 34f54ec

Please sign in to comment.