Skip to content

Commit 959ae79

Browse files
committed
fix(router dev): restore platform option functionality
1 parent 2110331 commit 959ae79

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

packages/qwik-router/src/buildtime/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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[];

packages/qwik-router/src/buildtime/vite/dev-middleware.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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);

packages/qwik-router/src/middleware/node/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isDev } from '@qwik.dev/core';
12
import { setServerPlatform } from '@qwik.dev/core/server';
23
import type { ClientConn, ServerRenderOptions } from '@qwik.dev/router/middleware/request-handler';
34
import {
@@ -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;

0 commit comments

Comments
 (0)