Skip to content

Commit eee5ffc

Browse files
committed
fix: lazy-resolve useRuntimeConfig in withSigning
Avoids pulling nitro virtual modules (#imports) into unit tests that import handler files for their exported utilities (e.g. instagram-embed exports rewriteUrl/scopeCss alongside its default handler). The dynamic import only runs at request time inside the nitro runtime where #imports is available.
1 parent 2b6605d commit eee5ffc

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/script/src/runtime/server/utils/withSigning.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121
*/
2222

2323
import type { EventHandler, EventHandlerRequest, EventHandlerResponse } from 'h3'
24-
import { useRuntimeConfig } from '#imports'
2524
import { createError, defineEventHandler } from 'h3'
2625
import { verifyProxyRequest } from './sign'
2726

2827
export function withSigning<Req extends EventHandlerRequest = EventHandlerRequest, Res extends EventHandlerResponse = EventHandlerResponse>(
2928
handler: EventHandler<Req, Res>,
3029
): EventHandler<Req, Res> {
3130
return defineEventHandler<Req>(async (event) => {
31+
// Lazy-resolve useRuntimeConfig to avoid pulling nitro's virtual modules
32+
// into unit tests that import handler files for their exported utilities
33+
// (e.g. instagram-embed.ts exports rewriteUrl / scopeCss alongside the handler).
34+
const { useRuntimeConfig } = await import('#imports')
3235
const runtimeConfig = useRuntimeConfig(event)
3336
const secret = (runtimeConfig['nuxt-scripts'] as { proxySecret?: string } | undefined)?.proxySecret
3437

0 commit comments

Comments
 (0)