diff --git a/client/src/pages/MapView.jsx b/client/src/pages/MapView.jsx index fd0183f..09ab61a 100644 --- a/client/src/pages/MapView.jsx +++ b/client/src/pages/MapView.jsx @@ -423,11 +423,7 @@ const MapView = () => { // Calculate values first const totalDrones = detections.length; - const opacity = getDetectionOpacity(detection); - const age = getDetectionAge(detection); - console.log('MapView: Detection age:', age, 'opacity:', opacity); - - // Calculate ring radius based on RSSI (rough distance estimation) + // Define helper functions first before using them const getRssiRadius = (rssi) => { if (rssi > -40) return 100; // <100m - very close if (rssi > -60) return 500; // ~500m - close @@ -437,10 +433,6 @@ const MapView = () => { return 15000; // ~15km - maximum range }; - const radius = getRssiRadius(detection.rssi); - console.log('MapView: Ring radius:', radius, 'for RSSI:', detection.rssi); - - // Color based on threat level and multiple drone differentiation const getRingColor = (rssi, droneType, droneIndex, totalDrones) => { // Orlan drones (type 1) always red if (droneType === 1) return '#dc2626'; // red-600 @@ -466,9 +458,6 @@ const MapView = () => { return '#16a34a'; // green-600 - far }; - const ringColor = getRingColor(detection.rssi, detection.drone_type, droneIndex, totalDrones); - - // Different visual styles for multiple drones at same detector const getDashPattern = (droneType, droneIndex, totalDrones) => { if (droneType === 1) return null; // Orlan always solid @@ -485,7 +474,6 @@ const MapView = () => { return patterns[droneIndex % patterns.length]; }; - // Slight offset for multiple rings to make them more visible const getPositionOffset = (droneIndex, totalDrones) => { if (totalDrones === 1) return [0, 0]; @@ -497,6 +485,15 @@ const MapView = () => { ]; }; + // Now calculate values using the functions + const opacity = getDetectionOpacity(detection); + const age = getDetectionAge(detection); + console.log('MapView: Detection age:', age, 'opacity:', opacity); + + const radius = getRssiRadius(detection.rssi); + console.log('MapView: Ring radius:', radius, 'for RSSI:', detection.rssi); + + const ringColor = getRingColor(detection.rssi, detection.drone_type, droneIndex, totalDrones); const dashPattern = getDashPattern(detection.drone_type, droneIndex, totalDrones); const [latOffset, lonOffset] = getPositionOffset(droneIndex, totalDrones); diff --git a/server/index.js b/server/index.js index 1c4ed6f..8f319c8 100644 --- a/server/index.js +++ b/server/index.js @@ -19,6 +19,10 @@ const errorHandler = require('./middleware/errorHandler'); const { apiDebugMiddleware } = require('./utils/apiDebugLogger'); const app = express(); + +// Trust proxy headers for getting real client IPs behind nginx +app.set('trust proxy', true); + const server = createServer(app); const io = new Server(server, { cors: { diff --git a/server/services/socketService.js b/server/services/socketService.js index ca0faea..2869a76 100644 --- a/server/services/socketService.js +++ b/server/services/socketService.js @@ -1,6 +1,11 @@ function initializeSocketHandlers(io) { io.on('connection', (socket) => { - const clientIP = socket.handshake.address || socket.request.connection.remoteAddress || 'unknown'; + // Get real client IP from proxy headers (nginx forwarded headers) + const clientIP = socket.handshake.headers['x-forwarded-for']?.split(',')[0]?.trim() || + socket.handshake.headers['x-real-ip'] || + socket.handshake.address || + socket.request.connection.remoteAddress || + 'unknown'; console.log(`Client connected: ${socket.id} from IP: ${clientIP}`); // Join device-specific rooms for targeted updates