mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): throw 404 when accessing /__nuxt_error
directly (#20497)
This commit is contained in:
parent
4c200e4a2a
commit
200cb2787e
@ -180,7 +180,10 @@ export default defineRenderHandler(async (event) => {
|
||||
}
|
||||
|
||||
if (ssrError && event.node.req.socket.readyState !== 'readOnly' /* direct request */) {
|
||||
throw createError('Cannot directly render error page!')
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Page Not Found: /__nuxt_error'
|
||||
})
|
||||
}
|
||||
|
||||
// Check for island component rendering
|
||||
|
@ -574,6 +574,25 @@ describe('errors', () => {
|
||||
expect(await res.text()).toContain('This is a custom error')
|
||||
})
|
||||
|
||||
it('should not allow accessing error route directly', async () => {
|
||||
const res = await fetch('/__nuxt_error', {
|
||||
headers: {
|
||||
accept: 'application/json'
|
||||
}
|
||||
})
|
||||
expect(res.status).toBe(404)
|
||||
const error = await res.json()
|
||||
delete error.stack
|
||||
expect(error).toMatchInlineSnapshot(`
|
||||
{
|
||||
"message": "Page Not Found: /__nuxt_error",
|
||||
"statusCode": 404,
|
||||
"statusMessage": "Page Not Found: /__nuxt_error",
|
||||
"url": "/__nuxt_error",
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
// TODO: need to create test for webpack
|
||||
it.runIf(!isDev() && !isWebpack)('should handle chunk loading errors', async () => {
|
||||
const { page, consoleLogs } = await renderPage('/')
|
||||
|
Loading…
Reference in New Issue
Block a user