This commit is contained in:
Raven Scott
2025-12-17 20:05:50 -05:00
commit 742e27d3f7
276 changed files with 89838 additions and 0 deletions
@@ -0,0 +1,41 @@
const state = require('../../../infrastructure/state');
const { cleanupInterfaces } = require('../../../maintenance/cleanup');
const { logError } = require('../../../infrastructure/logger');
const { broadcast } = require('../websocket');
async function handleInterfacesRoutes(req, res) {
const urlPath = req.urlPath || new URL(req.url, `https://${req.headers.host}`).pathname;
const method = req.method;
if (method === 'GET' && urlPath === '/api/interfaces') {
try {
const interfaces = Array.from(state.domainToIPMap.entries()).map(([domain, ip]) => ({ domain, ip }));
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(interfaces));
} catch (err) {
logError('Admin', `Failed to fetch interfaces: ${err.message}`);
res.writeHead(500);
res.end(JSON.stringify({ error: 'Failed to fetch interfaces' }));
}
return true;
}
if (method === 'POST' && urlPath === '/api/cleanup-interfaces') {
try {
await cleanupInterfaces();
broadcast({ type: 'update-interfaces' });
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('OK');
} catch (err) {
logError('Admin', `Failed to cleanup interfaces: ${err.message}`);
res.writeHead(500);
res.end(err.message);
}
return true;
}
return false;
}
module.exports = { handleInterfacesRoutes };