// Middleware to log the request details
export function logRequestDetails(req, res, next) {
  console.log(`<<< Received ${req.method} request for ${req.url}`)
  const maskedHeaders = {
    ...req.headers,
    authorization: req.headers.authorization?.replace(/(Bearer\s)cf-(.*)(.{4})/, "$1cf-****$3"),
  }
  console.log(`<<< Request headers: ${JSON.stringify(maskedHeaders)}`)
  console.log(`<<< Request params: ${JSON.stringify(req.params)}`)
  console.log(`<<< Request query: ${JSON.stringify(req.query)}`)
  next()
}

export function logRequestBody(req, res, next) {
  console.log(`<<< Request body: ${JSON.stringify(req.body)}`)
  next()
}
