Skip to content

Commit

Permalink
feat: expose whole cloudflare context (#3931)
Browse files Browse the repository at this point in the history
fixes #3655
  • Loading branch information
manucorporat committed Apr 26, 2023
1 parent cf160d7 commit fadc9e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions packages/qwik-city/middleware/cloudflare-pages/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import type { ServerRenderOptions } from '@builder.io/qwik-city/middleware/request-handler';

// @public (undocumented)
export function createQwikCity(opts: QwikCityCloudflarePagesOptions): ({ request, env, waitUntil, next }: EventPluginContext) => Promise<Response>;
export function createQwikCity(opts: QwikCityCloudflarePagesOptions): (ctx: EventPluginContext) => Promise<Response>;

// @public (undocumented)
export interface EventPluginContext {
Expand All @@ -24,7 +24,11 @@ export interface EventPluginContext {
// @public (undocumented)
export interface PlatformCloudflarePages {
// (undocumented)
env?: EventPluginContext['env'];
env: EventPluginContext['env'];
// (undocumented)
request: EventPluginContext['env'];
// (undocumented)
waitUntil: EventPluginContext['waitUntil'];
}

// @public (undocumented)
Expand Down
9 changes: 6 additions & 3 deletions packages/qwik-city/middleware/cloudflare-pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export function createQwikCity(opts: QwikCityCloudflarePagesOptions) {
if (opts.manifest) {
setServerPlatform(opts.manifest);
}
async function onCloudflarePagesRequest({ request, env, waitUntil, next }: EventPluginContext) {
async function onCloudflarePagesRequest(ctx: EventPluginContext) {
try {
const { request, env, waitUntil, next } = ctx;
const url = new URL(request.url);

if (isStaticPath(request.method, url)) {
Expand Down Expand Up @@ -69,7 +70,7 @@ export function createQwikCity(opts: QwikCityCloudflarePagesOptions) {
resolve(response);
return writable;
},
platform: env,
platform: ctx,
};

// send request to qwik city request handler
Expand Down Expand Up @@ -130,7 +131,9 @@ export interface EventPluginContext {
* @public
*/
export interface PlatformCloudflarePages {
env?: EventPluginContext['env'];
request: EventPluginContext['env'];
waitUntil: EventPluginContext['waitUntil'];
env: EventPluginContext['env'];
}

const resolved = Promise.resolve();
Expand Down

0 comments on commit fadc9e0

Please sign in to comment.