diff --git a/package-lock.json b/package-lock.json index 8ee6bd1d6..f54504ec3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "darwin" ], "dependencies": { + "@fastify/helmet": "8.0.0", "@hapi/boom": "9.1.4", "@snyk/protect": "1.907.0", "fastify": "3.28.0", @@ -490,6 +491,15 @@ "ajv": "^6.12.6" } }, + "node_modules/@fastify/helmet": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@fastify/helmet/-/helmet-8.0.0.tgz", + "integrity": "sha512-ZH44iLUmXNfYDyfHDbTTbewKrrGG/SBAkgju5RiIYVbOfyKfXGzxq1Om9RyXTSn5fKvNT//Ew71dPdiKg0fjoQ==", + "dependencies": { + "fastify-plugin": "^3.0.0", + "helmet": "^5.0.1" + } + }, "node_modules/@hapi/boom": { "version": "9.1.4", "resolved": "https://registry.npmjs.org/@hapi/boom/-/boom-9.1.4.tgz", @@ -2856,6 +2866,14 @@ "he": "bin/he" } }, + "node_modules/helmet": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-5.0.2.tgz", + "integrity": "sha512-QWlwUZZ8BtlvwYVTSDTBChGf8EOcQ2LkGMnQJxSzD1mUu8CCjXJZq/BXP8eWw4kikRnzlhtYo3lCk0ucmYA3Vg==", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", @@ -6673,6 +6691,15 @@ "ajv": "^6.12.6" } }, + "@fastify/helmet": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@fastify/helmet/-/helmet-8.0.0.tgz", + "integrity": "sha512-ZH44iLUmXNfYDyfHDbTTbewKrrGG/SBAkgju5RiIYVbOfyKfXGzxq1Om9RyXTSn5fKvNT//Ew71dPdiKg0fjoQ==", + "requires": { + "fastify-plugin": "^3.0.0", + "helmet": "^5.0.1" + } + }, "@hapi/boom": { "version": "9.1.4", "resolved": "https://registry.npmjs.org/@hapi/boom/-/boom-9.1.4.tgz", @@ -8508,6 +8535,11 @@ "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true }, + "helmet": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-5.0.2.tgz", + "integrity": "sha512-QWlwUZZ8BtlvwYVTSDTBChGf8EOcQ2LkGMnQJxSzD1mUu8CCjXJZq/BXP8eWw4kikRnzlhtYo3lCk0ucmYA3Vg==" + }, "hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", diff --git a/package.json b/package.json index d0c188f74..33b46adc1 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,9 @@ }, "homepage": "https://github.com/timoa/nodejs-encryption-api-example#readme", "dependencies": { - "@snyk/protect": "1.907.0", + "@fastify/helmet": "8.0.0", "@hapi/boom": "9.1.4", + "@snyk/protect": "1.907.0", "fastify": "3.28.0", "fastify-healthcheck": "3.1.0", "fastify-swagger": "5.1.1", diff --git a/src/index.js b/src/index.js index 75b42b9fc..d4507b661 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,8 @@ const fastify = require('fastify')(); +const fastifyHelmet = require('@fastify/helmet'); +const fastifyHealthcheck = require('fastify-healthcheck'); +const fastifySwagger = require('fastify-swagger'); + const logger = require('./lib/logger'); const config = require('./config/config.json'); const routes = require('./routes'); @@ -10,8 +14,13 @@ const port = process.env.NODE_PORT || config.app.port; // Connect to MongoDB db.connect(); +// Register Helmet +fastify.register(fastifyHelmet, { + global: true, +}); + // Register the Health plugin -fastify.register(require('fastify-healthcheck'), { +fastify.register(fastifyHealthcheck, { healthcheckUrl: `/${config.healthCheck.path}`, }); @@ -19,7 +28,7 @@ fastify.register(require('fastify-healthcheck'), { const swagger = require('./swagger/options'); // Register the Swagger plugin -fastify.register(require('fastify-swagger'), swagger.options); +fastify.register(fastifySwagger, swagger.options); // Load the routes routes.forEach((route) => {