mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
fix(nuxt): pass event to useRuntimeConfig
in Nuxt renderer (#26058)
This commit is contained in:
parent
75278ca8fb
commit
2e1530c6b4
@ -55,7 +55,7 @@ export default <NitroErrorHandler> async function errorhandler (error: H3Error,
|
||||
|
||||
// HTML response (via SSR)
|
||||
const res = isRenderingError ? null : await useNitroApp().localFetch(
|
||||
withQuery(joinURL(useRuntimeConfig().app.baseURL, '/__nuxt_error'), errorObject),
|
||||
withQuery(joinURL(useRuntimeConfig(event).app.baseURL, '/__nuxt_error'), errorObject),
|
||||
{
|
||||
headers: { ...reqHeaders, 'x-nuxt-error': 'true' },
|
||||
redirect: 'manual'
|
||||
|
@ -2,10 +2,12 @@ import { joinURL } from 'ufo'
|
||||
import { useRuntimeConfig } from '#internal/nitro'
|
||||
|
||||
export function baseURL (): string {
|
||||
// TODO: support passing event to `useRuntimeConfig`
|
||||
return useRuntimeConfig().app.baseURL
|
||||
}
|
||||
|
||||
export function buildAssetsDir (): string {
|
||||
// TODO: support passing event to `useRuntimeConfig`
|
||||
return useRuntimeConfig().app.buildAssetsDir as string
|
||||
}
|
||||
|
||||
@ -14,6 +16,7 @@ export function buildAssetsURL (...path: string[]): string {
|
||||
}
|
||||
|
||||
export function publicAssetsURL (...path: string[]): string {
|
||||
// TODO: support passing event to `useRuntimeConfig`
|
||||
const app = useRuntimeConfig().app
|
||||
const publicBase = app.cdnURL as string || app.baseURL
|
||||
return path.length ? joinURL(publicBase, ...path) : publicBase
|
||||
|
@ -158,7 +158,7 @@ const getSPARenderer = lazyCachedFunction(async () => {
|
||||
const result = await renderer.renderToString({})
|
||||
|
||||
const renderToString = (ssrContext: NuxtSSRContext) => {
|
||||
const config = useRuntimeConfig()
|
||||
const config = useRuntimeConfig(ssrContext.event)
|
||||
ssrContext.modules = ssrContext.modules || new Set<string>()
|
||||
ssrContext!.payload = {
|
||||
_errors: {},
|
||||
@ -288,7 +288,7 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
|
||||
const ssrContext: NuxtSSRContext = {
|
||||
url,
|
||||
event,
|
||||
runtimeConfig: useRuntimeConfig() as NuxtSSRContext['runtimeConfig'],
|
||||
runtimeConfig: useRuntimeConfig(event) as NuxtSSRContext['runtimeConfig'],
|
||||
noSSR:
|
||||
!!(process.env.NUXT_NO_SSR) ||
|
||||
event.context.nuxt?.noSSR ||
|
||||
@ -311,7 +311,7 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
|
||||
|
||||
// Whether we are prerendering route
|
||||
const _PAYLOAD_EXTRACTION = import.meta.prerender && process.env.NUXT_PAYLOAD_EXTRACTION && !ssrContext.noSSR && !isRenderingIsland
|
||||
const payloadURL = _PAYLOAD_EXTRACTION ? joinURL(useRuntimeConfig().app.baseURL, url, process.env.NUXT_JSON_PAYLOADS ? '_payload.json' : '_payload.js') : undefined
|
||||
const payloadURL = _PAYLOAD_EXTRACTION ? joinURL(ssrContext.runtimeConfig.app.baseURL, url, process.env.NUXT_JSON_PAYLOADS ? '_payload.json' : '_payload.js') : undefined
|
||||
if (import.meta.prerender) {
|
||||
ssrContext.payload.prerenderedAt = Date.now()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user