mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
fix(nuxt): disallow directly rendering error page (#8673)
This commit is contained in:
parent
ea17148a6b
commit
253c8f7ee0
@ -1,7 +1,7 @@
|
|||||||
import { createRenderer, renderResourceHeaders } from 'vue-bundle-renderer/runtime'
|
import { createRenderer, renderResourceHeaders } from 'vue-bundle-renderer/runtime'
|
||||||
import type { RenderResponse } from 'nitropack'
|
import type { RenderResponse } from 'nitropack'
|
||||||
import type { Manifest } from 'vite'
|
import type { Manifest } from 'vite'
|
||||||
import { appendHeader, getQuery, writeEarlyHints } from 'h3'
|
import { appendHeader, createError, getQuery, writeEarlyHints } from 'h3'
|
||||||
import devalue from '@nuxt/devalue'
|
import devalue from '@nuxt/devalue'
|
||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
import { renderToString as _renderToString } from 'vue/server-renderer'
|
import { renderToString as _renderToString } from 'vue/server-renderer'
|
||||||
@ -121,6 +121,10 @@ export default defineRenderHandler(async (event) => {
|
|||||||
const ssrError = event.req.url?.startsWith('/__nuxt_error')
|
const ssrError = event.req.url?.startsWith('/__nuxt_error')
|
||||||
? getQuery(event) as Exclude<NuxtApp['payload']['error'], Error>
|
? getQuery(event) as Exclude<NuxtApp['payload']['error'], Error>
|
||||||
: null
|
: null
|
||||||
|
if (ssrError && event.req.socket.readyState !== 'readOnly' /* direct request */) {
|
||||||
|
throw createError('Cannot directly render error page!')
|
||||||
|
}
|
||||||
|
|
||||||
let url = ssrError?.url as string || event.req.url!
|
let url = ssrError?.url as string || event.req.url!
|
||||||
|
|
||||||
// Whether we are rendering payload route
|
// Whether we are rendering payload route
|
||||||
|
Loading…
Reference in New Issue
Block a user