From b90925ad4105815f3831e67f2fabd60f1b0bc3a2 Mon Sep 17 00:00:00 2001 From: AirBorne04 Date: Wed, 19 Oct 2022 15:59:40 +0200 Subject: [PATCH] added get runtime api added context to the runtime in "advanced" mode --- packages/integrations/cloudflare/package.json | 3 ++- packages/integrations/cloudflare/src/runtime.ts | 7 +++++++ packages/integrations/cloudflare/src/server.advanced.ts | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 packages/integrations/cloudflare/src/runtime.ts diff --git a/packages/integrations/cloudflare/package.json b/packages/integrations/cloudflare/package.json index b33216c090637..df1348a18868a 100644 --- a/packages/integrations/cloudflare/package.json +++ b/packages/integrations/cloudflare/package.json @@ -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", @@ -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" diff --git a/packages/integrations/cloudflare/src/runtime.ts b/packages/integrations/cloudflare/src/runtime.ts new file mode 100644 index 0000000000000..a56360a88367e --- /dev/null +++ b/packages/integrations/cloudflare/src/runtime.ts @@ -0,0 +1,7 @@ + +export function getRuntime(request: Request): any { + return Reflect.get( + request, + Symbol.for('runtime') + ); +} \ No newline at end of file diff --git a/packages/integrations/cloudflare/src/server.advanced.ts b/packages/integrations/cloudflare/src/server.advanced.ts index f75196ea07463..a63e173d93f73 100644 --- a/packages/integrations/cloudflare/src/server.advanced.ts +++ b/packages/integrations/cloudflare/src/server.advanced.ts @@ -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"; @@ -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);