diff --git a/README.md b/README.md index adc422f..70a93d0 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ fastify application hook onClose|Add the fastify onClose application hook|ffoncl fastify application hook onRoute|Add the fastify onRoute application hook|ffonroute, hookonroute fastify application hook onRegister|Add the fastify onRegister application hook|ffonregister, hookonregister fastify add schema|Add a shared JSON schema to fastify|ffaddschema, ffsharedschema, ffjsonschema, ffschema +fastify not found handler|Add the default 404 not found handler|ffnotfound, ff404 ## Contribute diff --git a/snippets/snippets-js.json b/snippets/snippets-js.json index 0098fbb..3533dd7 100644 --- a/snippets/snippets-js.json +++ b/snippets/snippets-js.json @@ -273,5 +273,25 @@ "fastify.addSchema($0)" ], "description": "Add a shared JSON schema to fastify" + }, + "fastify not found handler": { + "scope": "javascript,typescript", + "prefix": [ + "ffnotfound", + "ff404" + ], + "body": [ + "fastify.setNotFoundHandler(function basic404(request, reply) {", + " const { url, method } = request.raw", + " const message = `Route ${method}:${url} not found`", + " request.log.info(message)", + " reply.code(404).send({", + " message,", + " error: 'Not Found',", + " statusCode: 404", + " })", + "})" + ], + "description": "Add the default 404 not found handler" } } \ No newline at end of file