Created
December 10, 2021 12:55
-
-
Save abelaska/12b6b838dfe1ff58ee3a61600472c612 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FastifyPluginAsync } from 'fastify'; | |
import fp from 'fastify-plugin'; | |
// https://www.fastify.io/docs/latest/TypeScript/#creating-a-typescript-fastify-plugin | |
const securityHeadersPlugin: FastifyPluginAsync = async (fastify) => { | |
fastify.addHook('onRequest', async (_req, res) => { | |
res.header('Strict-Transport-Security', 'max-age=31536000; includeSubDomains; preload'); | |
res.header('X-Content-Type-Options', 'nosniff'); | |
}); | |
}; | |
export const securityHeadersFastifyPlugin = fp(securityHeadersPlugin, { | |
fastify: '^3.24.0', | |
name: 'fastify-security-headers', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment