Skip to content

Sending file with 404 status code dont work #474

@MatyasZERO

Description

@MatyasZERO

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.0.0

Plugin version

8.0.1

Node.js version

20.9.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

11

Description

Sending file with 404 status code dont work, see the code below.
On fastify version 4.28.1 and plugin version this worked normally.

const fastify = require('fastify')({logger: true})
const path = require('node:path')

fastify.register(require('@fastify/static'), {
  root: path.join(__dirname, 'public'),
  prefix: '/',
})


fastify.setNotFoundHandler((req, reply) => {
  return reply.code(404).type("text/html").sendFile("404.html")
  // this send the file with 200 status code
})

// Run the server!
fastify.listen({ port: 3000 })
const fastify = require('fastify')({logger: true})
const path = require('node:path')

fastify.register(require('@fastify/static'), {
  root: path.join(__dirname, 'public'),
  prefix: '/',
})


fastify.setNotFoundHandler((req, reply) => {
  return reply.code(404).type("text/html").send("Hello world")
  // this send the Hello world message with 404 status code
})

// Run the server!
fastify.listen({ port: 3000 })

Link to code that reproduces the bug

No response

Expected Behavior

It should send file with 404 status code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions