Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(document-driven): Only set 404 status on SSR #1409

Merged
merged 4 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 { useNuxtApp, useContent, useContentHead } 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
const nuxtApp = useNuxtApp()
if (!page.value && process.server && nuxtApp.ssrContext) {
nuxtApp.ssrContext.res.statusCode = 404
Atinux marked this conversation as resolved.
Show resolved Hide resolved
}

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('Document not found')
}
})
})