@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
25 lines (24 loc) • 635 B
JavaScript
import * as n from "node:os";
function i() {
const o = n.networkInterfaces();
for (const r of Object.values(o))
if (r) {
for (const e of r)
if (e.family === "IPv4" && !e.internal)
return e.address;
}
}
function f(o) {
const r = o.address();
if (!r || typeof r == "string") throw new Error("Server is not listening or address is a pipe");
let { address: e, port: s } = r;
if (e === "::1" || e === "127.0.0.1") e = "localhost";
else if (e === "::" || e === "0.0.0.0") {
const t = i();
t && (e = t);
}
return { address: e, port: s };
}
export {
f as getReadableServerAddress
};