-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the issue has not already been raised
Issue
The setDefaultRoute method takes a function of the signature (RawRequest, RawReply) =>. This is unlike all the other handlers, such as setNotFoundHandler, which expects a function like (FastifyRequest, FastifyReply) =>. This can lead to subtle bugs, as the input parameters have slightly different properties. If possible, please fix this before releasing Fastify 4. It would be a shame if this breaking change had to wait until Fastify 5.
For context, my app passes the same handler to both setDefaultRoute and setNotFoundHandler:
app.setDefaultRoute(serveIndexHtmlHandler)
app.setNotFoundHandler(serveIndexHtmlHandler)All that each of these do is serve a static index.html file. Upon reading other issues in this repo, I perhaps don't need setDefaultRoute at all in my case; but if my app did want a certain HTML file returned for / and a separate error HTML file returned for 404 routes, I would still need both (I think).
The handler was initially implemented like this:
const serveIndexHtmlHandler = (request, reply) => {
reply.sendFile('index.html')
}This works fine for setNotFoundHandler, but not setDefaultRoute, because RawMessage lacks the sendFile method. This took a substantial amount of debugging to discover.