File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -130,7 +130,13 @@ export interface PluginOptions {
130130 mdxPlugins ?: MdxPlugins ;
131131 /** MDX Options https://mdxjs.com/ */
132132 mdx ?: any ;
133- /** The platform object which can be used to mock the Cloudflare bindings. */
133+ /**
134+ * Extend the `platform` object in RequestEvent, which can be used to e.g. mock Cloudflare
135+ * bindings.
136+ *
137+ * This only works in **dev mode** and only when using the in-process Vite dev server middleware
138+ * (the default).
139+ */
134140 platform ?: Record < string , unknown > ;
135141 /** Configuration to rewrite url paths */
136142 rewriteRoutes ?: RewriteRouteOption [ ] ;
Original file line number Diff line number Diff line change @@ -63,7 +63,11 @@ export const makeRouterDevMiddleware =
6363 const render = ( async ( opts : RendererOptions ) => {
6464 return await renderer ( opts as any ) ;
6565 } ) as Render ;
66- const { router, staticFile, notFound } = createQwikRouter ( { render } ) ;
66+ const { router, staticFile, notFound } = createQwikRouter ( {
67+ render,
68+ // inject the platform from dev middleware options
69+ platform : ctx . opts . platform ,
70+ } as any ) ;
6771
6872 // Wrap the response to enable HTML transformation
6973 const wrappedRes = wrapResponseForHtmlTransform ( req , res , server ) ;
Original file line number Diff line number Diff line change 1+ import { isDev } from '@qwik.dev/core' ;
12import { setServerPlatform } from '@qwik.dev/core/server' ;
23import type { ClientConn , ServerRenderOptions } from '@qwik.dev/router/middleware/request-handler' ;
34import {
@@ -42,6 +43,10 @@ export function createQwikRouter(opts: QwikRouterNodeRequestOptions | QwikCityNo
4243 'server' ,
4344 opts . getClientConn
4445 ) ;
46+ // In dev mode, inject platform from options via secret property
47+ if ( isDev && ( opts as any ) . platform ) {
48+ Object . assign ( serverRequestEv . platform , ( opts as any ) . platform ) ;
49+ }
4550 const handled = await requestHandler ( serverRequestEv , opts ) ;
4651 if ( handled ) {
4752 const err = await handled . completion ;
You can’t perform that action at this time.
0 commit comments