I want to set response status 404 on my /not-found page. I tried to:
- create custom error page in ~/error.vue and throw fatal errors with
createError. But it just sends 200 - throw fatal errors and use NuxtErrorBoundary. But it doesn't do anything
- use setResponseStatus in setup
const event = useRequestEvent()
setResponseStatus(event, 404)
setResponseStatus(event, 404, 'Page Not Found')
But it must be executed (as they say) on the server, so it doesn't always work on setup.
- Use middleware in
~/server/middleware):
// setResponseStatus wasn't defined in all ~/server/*
// so I had to import it from here
import { setResponseStatus } from '../../node_modules/nuxt/dist/app'
export default defineEventHandler((event) => {
setResponseStatus(event, 404)
})
Which either does nothing or just causes nuxt instance unavailble error.
It shouldn't so complicated, right? Or what am I missing here?
Currently considering handling 404 in nginx instead.
