import { createServer } from 'node:http'; import { execSync } from 'node:child_process'; const server = createServer(async function (req, res) { Object.entries({ 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': '*', }).forEach(([key, value]) => { res.setHeader(key, value); }); let result = {}; try { result = { hostname: execSync('hostname', { encoding: 'utf8' }).trim(), ip: execSync("ip -4 addr show eth0 | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'", { encoding: 'utf8' }).trim(), }; } catch(err) {} res.writeHead(200); res.end(JSON.stringify(result)); }); let PORT = process.env.NODE_PORT || process.env.PORT || 3000; server.listen(PORT, () => console.log(`Running at ${PORT}`));