/**
 * Common middleware utilities
 */
import { randomUUID } from 'crypto';
/**
 * Add correlation ID middleware
 */
export function addCorrelationId(server) {
    server.addHook('onRequest', async (request, reply) => {
        const correlationId = request.headers['x-request-id'] || randomUUID();
        request.id = correlationId;
        reply.header('x-request-id', correlationId);
    });
}
/**
 * Add request logging middleware
 */
export function addRequestLogging(server) {
    server.addHook('onRequest', async (request) => {
        request.log.info({
            method: request.method,
            url: request.url,
            ip: request.ip,
            userAgent: request.headers['user-agent'],
        });
    });
    server.addHook('onResponse', async (request, reply) => {
        request.log.info({
            method: request.method,
            url: request.url,
            statusCode: reply.statusCode,
            responseTime: reply.getResponseTime(),
        });
    });
}
//# sourceMappingURL=middleware.js.map