Skip to content

Commit

Permalink
fix(document-driven): Only set 404 status on SSR (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux authored and farnabaz committed Sep 7, 2022
1 parent 406fced commit 7e34443
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 2 additions & 0 deletions playground/document-driven/content/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ description: Hello, here is a description
# Home

Hello World!

[404](/404)
13 changes: 5 additions & 8 deletions src/runtime/pages/document-driven.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<script setup lang="ts">
import { createError } from 'h3'
import { useContent, useContentHead, useRoute } from '#imports'
import { useContent, useContentHead, useRequestEvent } from '#imports'
const { page } = useContent()
// Page not found
if (!page.value) {
throw createError({
statusCode: 404,
statusMessage: `Page not found: ${useRoute().path}`
})
// Page not found, set correct status code on SSR
if (!page.value && process.server) {
const event = useRequestEvent()
event.res.statusCode = 404
}
useContentHead(page)
Expand Down
2 changes: 1 addition & 1 deletion test/document-driven.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('fixtures:document-driven', async () => {
await $fetch('/page-not-found')
} catch (e) {
expect(e.response.status).toBe(404)
expect(e.response.statusText).toBe('Page not found: /page-not-found')
expect(e.response.statusText).toBe('Not Found')
}
})
})

0 comments on commit 7e34443

Please sign in to comment.