From 72d61d1bf450a9084e57c941135423216b2e2c8a Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Wed, 26 May 2021 07:33:55 +0200 Subject: [PATCH 1/2] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 64a5372..578b952 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fastify-snippets", - "version": "1.0.0", + "version": "1.0.1", "icon": "images/logo-256.png", "displayName": "Fastify Snippets", "description": "Make your Fastify developing even faster", From c84c71ecab58c9107efd8d6d877e3bb37dc6d273 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Fri, 2 Jul 2021 08:24:05 +0200 Subject: [PATCH 2/2] add setNotFoundHandler snippet --- README.md | 1 + snippets/snippets-js.json | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) 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