Skip to content

Instantly share code, notes, and snippets.

@abelaska
Created December 10, 2021 12:55
Show Gist options
  • Save abelaska/12b6b838dfe1ff58ee3a61600472c612 to your computer and use it in GitHub Desktop.
Save abelaska/12b6b838dfe1ff58ee3a61600472c612 to your computer and use it in GitHub Desktop.
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