Files
p2ns/includes/admin/routes/peers.js
T
2025-12-17 20:05:50 -05:00

26 lines
770 B
JavaScript

const state = require('../../infrastructure/state');
const { logError } = require('../../infrastructure/logger');
async function handlePeersRoutes(req, res) {
const urlPath = req.urlPath || new URL(req.url, `https://${req.headers.host}`).pathname;
const method = req.method;
if (method === 'GET' && urlPath === '/api/peers') {
try {
const peers = Array.from(state.connectedPeers);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(peers));
} catch (err) {
logError('Admin', `Failed to fetch peers: ${err.message}`);
res.writeHead(500);
res.end(JSON.stringify({ error: 'Failed to fetch peers' }));
}
return true;
}
return false;
}
module.exports = { handlePeersRoutes };