fastify 4.5.0 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/fastify.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const VERSION = '4.5.0'
3
+ const VERSION = '4.5.1'
4
4
 
5
5
  const Avvio = require('avvio')
6
6
  const http = require('http')
package/lib/context.js CHANGED
@@ -44,6 +44,7 @@ function Context ({
44
44
  this.onTimeout = null
45
45
  this.preHandler = null
46
46
  this.onResponse = null
47
+ this.preSerialization = null
47
48
  this.config = config
48
49
  this.errorHandler = errorHandler || server[kErrorHandler]
49
50
  this._middie = null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify",
3
- "version": "4.5.0",
3
+ "version": "4.5.1",
4
4
  "description": "Fast and low overhead web framework, for Node.js",
5
5
  "main": "fastify.js",
6
6
  "type": "commonjs",
@@ -710,3 +710,46 @@ test('preSerializationEnd should handle errors if the serialize method throws',
710
710
 
711
711
  t.end()
712
712
  })
713
+
714
+ t.test('nested hooks to do not crash on 404', t => {
715
+ t.plan(2)
716
+ const fastify = Fastify()
717
+
718
+ fastify.get('/hello', (req, reply) => {
719
+ reply.send({ hello: 'world' })
720
+ })
721
+
722
+ fastify.register(async function (fastify) {
723
+ fastify.get('/something', (req, reply) => {
724
+ reply.callNotFound()
725
+ })
726
+
727
+ fastify.setNotFoundHandler(async (request, reply) => {
728
+ reply.statusCode = 404
729
+ return { status: 'nested-not-found' }
730
+ })
731
+
732
+ fastify.setErrorHandler(async (error, request, reply) => {
733
+ reply.statusCode = 500
734
+ return { status: 'nested-error', error }
735
+ })
736
+ }, { prefix: '/nested' })
737
+
738
+ fastify.setNotFoundHandler(async (request, reply) => {
739
+ reply.statusCode = 404
740
+ return { status: 'not-found' }
741
+ })
742
+
743
+ fastify.setErrorHandler(async (error, request, reply) => {
744
+ reply.statusCode = 500
745
+ return { status: 'error', error }
746
+ })
747
+
748
+ fastify.inject({
749
+ method: 'GET',
750
+ url: '/nested/something'
751
+ }, (err, res) => {
752
+ t.error(err)
753
+ t.equal(res.statusCode, 404)
754
+ })
755
+ })