Fastify adapter for @http-policy/core — apply compiled HTTP policies via a Fastify plugin and hooks.
npm install @http-policy/core @http-policy/fastifyimport Fastify from 'fastify';
import { policy } from '@http-policy/core';
import { fastifyHttpPolicy, getPolicyHandle } from '@http-policy/fastify';
const apiPolicy = policy()
.security((s) => s.nosniff().hsts('180d').referrer('strict-origin-when-cross-origin'))
.cors((c) => c.origin(['https://app.example.com']).credentials())
.compile();
const app = Fastify();
await app.register(fastifyHttpPolicy, {
globalPolicy: apiPolicy,
});
app.get('/me', async (request, reply) => {
getPolicyHandle(request, reply).cache((c) => c.private().maxAge('30s'));
return { user: '…' };
});
await app.listen({ port: 3000 });The same policy definitions work unchanged with the Node.js, Express, Hono and NestJS adapters.
See the full documentation.