fastify / fastify/light-my-request

Add a custom not found handler

Open
#31 4 comments 0 reactions 0 assignees View on GitHub
feature request good first issue
Dominant language
JavaScript
Stars
420
Forks
55
Avg merge
13d 14h
Merged PRs (30d)
1

Description

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:
```js
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.