Skip to content

Commit 9e9f693

Browse files
committed
fix(google-maps): proxy registration order
1 parent 710f877 commit 9e9f693

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/module.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -319,24 +319,6 @@ export default defineNuxtModule<ModuleOptions>({
319319
if (unheadVersion?.startsWith('1')) {
320320
logger.error(`Nuxt Scripts requires Unhead >= 2, you are using v${unheadVersion}. Please run \`nuxi upgrade --clean\` to upgrade...`)
321321
}
322-
const googleMapsEnabled = config.googleStaticMapsProxy?.enabled || !!config.registry?.googleMaps
323-
nuxt.options.runtimeConfig['nuxt-scripts'] = {
324-
version: version!,
325-
// Private proxy config with API key (server-side only)
326-
googleStaticMapsProxy: googleMapsEnabled
327-
? { apiKey: (nuxt.options.runtimeConfig.public.scripts as any)?.googleMaps?.apiKey }
328-
: undefined,
329-
} as any
330-
nuxt.options.runtimeConfig.public['nuxt-scripts'] = {
331-
// expose for devtools
332-
version: nuxt.options.dev ? version : undefined,
333-
defaultScriptOptions: config.defaultScriptOptions as any,
334-
// Only expose enabled and cacheMaxAge to client, not apiKey
335-
googleStaticMapsProxy: googleMapsEnabled
336-
? { enabled: true, cacheMaxAge: config.googleStaticMapsProxy?.cacheMaxAge ?? 3600 }
337-
: undefined,
338-
} as any
339-
340322
// Normalize registry entries to [input, scriptOptions?] tuple form
341323
// Eliminates 4-shape polymorphism (true | 'mock' | object | array) for all downstream consumers
342324
if (config.registry) {
@@ -373,6 +355,26 @@ export default defineNuxtModule<ModuleOptions>({
373355
)
374356
}
375357

358+
// Setup runtimeConfig for proxies and devtools.
359+
// Must run AFTER env var resolution above so the API key is populated.
360+
const googleMapsEnabled = config.googleStaticMapsProxy?.enabled || !!config.registry?.googleMaps
361+
nuxt.options.runtimeConfig['nuxt-scripts'] = {
362+
version: version!,
363+
// Private proxy config with API key (server-side only)
364+
googleStaticMapsProxy: googleMapsEnabled
365+
? { apiKey: (nuxt.options.runtimeConfig.public.scripts as any)?.googleMaps?.apiKey }
366+
: undefined,
367+
} as any
368+
nuxt.options.runtimeConfig.public['nuxt-scripts'] = {
369+
// expose for devtools
370+
version: nuxt.options.dev ? version : undefined,
371+
defaultScriptOptions: config.defaultScriptOptions as any,
372+
// Only expose enabled and cacheMaxAge to client, not apiKey
373+
googleStaticMapsProxy: googleMapsEnabled
374+
? { enabled: true, cacheMaxAge: config.googleStaticMapsProxy?.cacheMaxAge ?? 3600 }
375+
: undefined,
376+
} as any
377+
376378
// Handle deprecation of bundle option
377379
if (config.defaultScriptOptions?.bundle !== undefined) {
378380
logger.warn(

0 commit comments

Comments
 (0)