fix(nuxt): use app.baseURL when fetching error page on server (#8888)

Co-authored-by: Toby Faux <tobyfaux@Tobys-MacBook-Pro.local>
This commit is contained in:
Toby Faux 2022-11-11 00:42:55 +11:00 committed by GitHub
parent 52c2bffa76
commit 3e34a61506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
import { withQuery } from 'ufo' import { joinURL, withQuery } from 'ufo'
import type { NitroErrorHandler } from 'nitropack' import type { NitroErrorHandler } from 'nitropack'
import { H3Error, setResponseHeader, getRequestHeaders } from 'h3' import { H3Error, setResponseHeader, getRequestHeaders } from 'h3'
import { useNitroApp } from '#internal/nitro' import { useNitroApp, useRuntimeConfig } from '#internal/nitro'
import { normalizeError, isJsonRequest } from '#internal/nitro/utils' import { normalizeError, isJsonRequest } from '#internal/nitro/utils'
export default <NitroErrorHandler> async function errorhandler (error: H3Error, event) { export default <NitroErrorHandler> async function errorhandler (error: H3Error, event) {
@ -47,7 +47,7 @@ export default <NitroErrorHandler> async function errorhandler (error: H3Error,
// HTML response (via SSR) // HTML response (via SSR)
const isErrorPage = event.req.url?.startsWith('/__nuxt_error') const isErrorPage = event.req.url?.startsWith('/__nuxt_error')
const res = !isErrorPage const res = !isErrorPage
? await useNitroApp().localFetch(withQuery('/__nuxt_error', errorObject), { ? await useNitroApp().localFetch(withQuery(joinURL(useRuntimeConfig().app.baseURL, '/__nuxt_error'), errorObject), {
headers: getRequestHeaders(event) as Record<string, string>, headers: getRequestHeaders(event) as Record<string, string>,
redirect: 'manual' redirect: 'manual'
}).catch(() => null) }).catch(() => null)