Skip to content

Commit

Permalink
Fixes #451
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor committed Nov 11, 2017
1 parent ff40e9a commit 8c528ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,9 @@ function build (options) {
}

function setNotFoundHandler (opts, handler) {
this.after(() => {
this.after((notHandledErr, done) => {
_setNotFoundHandler.call(this, opts, handler)
done(notHandledErr)
})
}

Expand Down
22 changes: 22 additions & 0 deletions test/404s.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,25 @@ test('hooks check 404', t => {
})
})
})

test('Issue #451', t => {
t.plan(1)

const fastify = Fastify()

fastify.get('/', function (req, reply) {
reply.send({ hello: 'world' })
})

fastify.get('/', function (req, reply) {
reply.send({ hello: 'world' })
})

fastify.setNotFoundHandler(function (req, reply) {
reply.code(404).send('this was not found')
})

fastify.listen(0, err => {
t.ok(err)
})
})

0 comments on commit 8c528ba

Please sign in to comment.