Production REST API with authentication, rate limiting, logging, and OpenAPI documentation.
import Fastify from 'fastify';
import jwt from '@fastify/jwt';
import rateLimit from '@fastify/rate-limit';
const app = Fastify({ logger: true });
app.register(jwt, { secret: process.env.JWT_SECRET });
app.register(rateLimit, { max: 100, timeWindow: '1m' });
app.get('/api/v1/users', {
preHandler: [app.authenticate],
}, async (req) => {
return { users: [] };
});Open in RoadCode