IO-2959 Add Crisp Status Reporter to API.
This commit is contained in:
26
server/utils/getHostNameOrIP.js
Normal file
26
server/utils/getHostNameOrIP.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// Load environment variables THIS MUST BE AT THE TOP
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
const { networkInterfaces, hostname } = require("node:os");
|
||||
|
||||
const getHostNameOrIP = () => {
|
||||
// Try to get the hostname first
|
||||
const hostName = hostname();
|
||||
if (hostName) return hostName;
|
||||
|
||||
const interfaces = networkInterfaces();
|
||||
for (const name of Object.keys(interfaces)) {
|
||||
for (const iface of interfaces[name]) {
|
||||
if (iface.family === "IPv4" && !iface.internal) {
|
||||
return iface.address;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "127.0.0.1";
|
||||
};
|
||||
|
||||
module.exports = getHostNameOrIP;
|
||||
Reference in New Issue
Block a user