@@ -3,7 +3,7 @@ import type { NuxtSSRContext } from 'nuxt/app'
33import type { OgImageOptions , OgImageOptionsInternal , OgImagePrebuilt , OgImageRuntimeConfig } from '../types'
44import { defu } from 'defu'
55import { stringify } from 'devalue'
6- import { useHead , useRuntimeConfig } from 'nuxt/app'
6+ import { useHead , useRequestEvent , useRuntimeConfig } from 'nuxt/app'
77import { joinURL , withQuery } from 'ufo'
88import { isRef , toValue } from 'vue'
99import { componentNames } from '#build/nuxt-og-image/components.mjs'
@@ -310,9 +310,8 @@ export interface GetOgImagePathResult {
310310 * @deprecated Use the return value of `defineOgImage()` instead, which now returns an array of generated paths.
311311 */
312312export function getOgImagePath ( _pagePath : string , _options ?: Partial < OgImageOptionsInternal > ) : GetOgImagePathResult {
313- const runtimeConfig = useRuntimeConfig ( )
314- const baseURL = runtimeConfig . app . baseURL
315- const { defaults, security } = useOgImageRuntimeConfig ( )
313+ const { app, defaults, security } = useOgImageRuntimeConfig ( )
314+ const baseURL = app . baseURL
316315 const extension = _options ?. extension || defaults ?. extension || 'png'
317316 // Force dynamic+signed URLs even during prerender when strict+secret are set.
318317 // Otherwise /_og/s/ URLs baked into HTML are unsigned and 403 at runtime for
@@ -337,13 +336,17 @@ export function getOgImagePath(_pagePath: string, _options?: Partial<OgImageOpti
337336}
338337
339338export function useOgImageRuntimeConfig ( ) {
340- const c = useRuntimeConfig ( )
339+ const event = import . meta. server ? useRequestEvent ( ) : undefined
340+ const c = event ? useRuntimeConfig ( event ) : useRuntimeConfig ( )
341341 // Server-side: full runtime config at the root key.
342342 // Client-side: the root key is stripped (server-only); only the non-sensitive subset
343343 // published under `public['nuxt-og-image']` is available. The secret never crosses.
344344 const serverCfg = ( c [ 'nuxt-og-image' ] as Record < string , any > | undefined ) || { }
345345 const publicCfg = ( c . public ?. [ 'nuxt-og-image' ] as Record < string , any > | undefined ) || { }
346346 const merged : Record < string , any > = { defaults : { } , ...publicCfg , ...serverCfg }
347+ const overrideSecret = ( c as Record < string , any > ) . ogImage ?. secret as string | undefined
348+ if ( overrideSecret )
349+ merged . security = { ...( merged . security || { } ) , secret : overrideSecret }
347350 merged . app = { baseURL : c . app . baseURL }
348351 return merged as any as OgImageRuntimeConfig
349352}
0 commit comments