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

Sending file with 404 status code dont work #474

Closed
2 tasks done
CZmatyasZERO opened this issue Oct 2, 2024 · 0 comments · Fixed by #476
Closed
2 tasks done

Sending file with 404 status code dont work #474

CZmatyasZERO opened this issue Oct 2, 2024 · 0 comments · Fixed by #476

Comments

@CZmatyasZERO
Copy link

CZmatyasZERO commented Oct 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant