Skip to content

Add a custom not found handler #31

Open
@delvedor

Description

@delvedor

Imagine that you are using fastify.inject to communicate with other endpoints of your app and sometime in the future you split to a microservices architecture; your code will break because the specific endpoint is no longer available in your app.
Would be cool have a custom 404 handler that will deal with that situation?

Eg:

const http = require('http')
const inject = require('light-my-request')

const dispatch = function (req, res) {
  const reply = 'Hello World'
  res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length })
  res.end(reply)
}

const notFound = function (req, res) {
  asyncCall(req, (err, body) => {
	res.end(body)
  })
}

const server = http.createServer(dispatch)

inject(dispatch, { method: 'get', url: '/', notFound }, (err, res) => {
  console.log(res.payload)
})

Then in Fastify we can think about how to encapsulate the inject's 404 handling as well.
Thoughts?

cc @fastify/fastify

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions