"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.requestLoggingMiddleware = void 0;
const crypto_1 = require("crypto");
const logging_1 = require("../../services/logging");
const logger = (0, logging_1.createLogger)('web-server:http');
function requestLoggingMiddleware(req, res, next) {
    const requestId = (0, crypto_1.randomUUID)();
    const startTime = Date.now();
    res.locals.ccsRequestId = requestId;
    res.setHeader('x-ccs-request-id', requestId);
    const shouldSkipLogging = req.originalUrl.startsWith('/api/logs');
    res.on('finish', () => {
        if (shouldSkipLogging) {
            return;
        }
        logger.info('request.completed', 'Dashboard request completed', {
            requestId,
            method: req.method,
            path: req.originalUrl,
            statusCode: res.statusCode,
            durationMs: Date.now() - startTime,
            remoteAddress: req.socket.remoteAddress || null,
            userAgent: req.headers['user-agent'] || null,
        });
    });
    next();
}
exports.requestLoggingMiddleware = requestLoggingMiddleware;
//# sourceMappingURL=request-logging-middleware.js.map