From 26c324b2f3b959cdf7992b5b9f937dc88084b7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Mon, 10 Jun 2024 15:53:27 -0600 Subject: [PATCH] cambiando forma de obtener IP local --- backend/src/constants/server.contants.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/backend/src/constants/server.contants.ts b/backend/src/constants/server.contants.ts index 29915945..b60118e6 100644 --- a/backend/src/constants/server.contants.ts +++ b/backend/src/constants/server.contants.ts @@ -1,20 +1,18 @@ import * as dotenv from 'dotenv'; +import * as network from 'network'; + +let publicIp: string; dotenv.config(); -import * as os from 'os'; -let ip = ''; -const interfaces = os.networkInterfaces(); -for (const interfaceName in interfaces) { - const networkInterfaces = interfaces[interfaceName]; - for (const networkInterface of networkInterfaces) { - if (networkInterface.family === 'IPv4' && !networkInterface.internal) { - ip = networkInterface.address; - } - } -} export class ServerConstants { static PORT: number = process.env.SERVER_PORT ? parseInt(process.env.SERVER_PORT) : 3003; - static IP: string = ip; - static HOST: string = `${ip || 'http://localhost'}:${this.PORT}`; + static IP: string = publicIp || 'http://localhost'; + static HOST: string = `${publicIp || 'http://localhost'}:${this.PORT}`; } + +network.get_private_ip(function (err, ip) { + publicIp = ip; + ServerConstants.IP = publicIp; + ServerConstants.HOST = `${publicIp}:${ServerConstants.PORT}`; +}); -- GitLab