Skip to content

Commit e8a0ed0

Browse files
authored
Merge pull request #92 from timoa/feature/fastify-helmet
Add Helmet support to secure HTTP headers
2 parents 3a7f31d + 89a7c41 commit e8a0ed0

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
},
3838
"homepage": "https://github.com/timoa/nodejs-encryption-api-example#readme",
3939
"dependencies": {
40-
"@snyk/protect": "1.907.0",
40+
"@fastify/helmet": "8.0.0",
4141
"@hapi/boom": "9.1.4",
42+
"@snyk/protect": "1.907.0",
4243
"fastify": "3.28.0",
4344
"fastify-healthcheck": "3.1.0",
4445
"fastify-swagger": "5.1.1",

src/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
const fastify = require('fastify')();
2+
const fastifyHelmet = require('@fastify/helmet');
3+
const fastifyHealthcheck = require('fastify-healthcheck');
4+
const fastifySwagger = require('fastify-swagger');
5+
26
const logger = require('./lib/logger');
37
const config = require('./config/config.json');
48
const routes = require('./routes');
@@ -10,16 +14,21 @@ const port = process.env.NODE_PORT || config.app.port;
1014
// Connect to MongoDB
1115
db.connect();
1216

17+
// Register Helmet
18+
fastify.register(fastifyHelmet, {
19+
global: true,
20+
});
21+
1322
// Register the Health plugin
14-
fastify.register(require('fastify-healthcheck'), {
23+
fastify.register(fastifyHealthcheck, {
1524
healthcheckUrl: `/${config.healthCheck.path}`,
1625
});
1726

1827
// Import Swagger Options
1928
const swagger = require('./swagger/options');
2029

2130
// Register the Swagger plugin
22-
fastify.register(require('fastify-swagger'), swagger.options);
31+
fastify.register(fastifySwagger, swagger.options);
2332

2433
// Load the routes
2534
routes.forEach((route) => {

0 commit comments

Comments
 (0)