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

Add a custom not found handler #31

Open
delvedor opened this issue Dec 17, 2018 · 4 comments
Open

Add a custom not found handler #31

delvedor opened this issue Dec 17, 2018 · 4 comments

Comments

@delvedor
Copy link
Member

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

@mcollina
Copy link
Member

This seems an interesting feature!

@cemremengu
Copy link
Contributor

If I am getting this right, it would be even cooler to have a redirect?

@delvedor
Copy link
Member Author

@cemremengu that would work as well :)

@RafaelGSS
Copy link
Member

@delvedor Can explain more this feature request? Is a notFound handler passed on inject options and in case of 404 code call the handler?

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

No branches or pull requests

4 participants