Skip to content

Commit e9521aa

Browse files
committed
obtengo globalServerIpAddress dinamicamente.
1 parent d393d8b commit e9521aa

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

controllers/servers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ app.post("/sendUsersOnline", function (req, res) {
1111
global.serversOnlineQuantityUsers = global.serversOnlineQuantityUsers.filter(x => x.ipAndPort !== serverInfo)
1212

1313
let serverName = req.body.serverName
14-
if (serverInfo === `93.176.180.82:7666`){
14+
15+
if (serverInfo.includes(global.serverIpAddress)){
1516
serverName = "Servidor Principal"
1617
}
1718

index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const express = require('express');
33
const path = require('path');
44
const cors = require('cors')
55
const bodyParser = require('body-parser');
6+
const https = require('https')
67
const app = express();
78
const port = process.env.PORT || 1337;
89
const db = require('./db');
@@ -21,6 +22,7 @@ const configFileManager = {
2122

2223
// usado en './controllers/servers';
2324
global.serversOnlineQuantityUsers = [];
25+
global.serverIpAddress = null;
2426

2527
app.use('/api/v1/users', require('./controllers/users'));
2628
app.use('/api/v1/charfiles', require('./controllers/charfiles'));
@@ -46,4 +48,32 @@ app.listen(port, function () {
4648
var datetime = new Date();
4749
var message = "Argentum Online API on Port:- " + port + " Started at :- " + datetime;
4850
console.log('\x1b[35m%s\x1b[0m', message);
51+
52+
53+
///Obtenemos IP del server donde se ejecuta la api.
54+
const options = {
55+
hostname: 'api.ipify.org',
56+
method: 'GET'
57+
}
58+
59+
var req = https.request(options, function(res) {
60+
// Buffer the body entirely for processing as a whole.
61+
var bodyChunks = [];
62+
res.on('data', function(chunk) {
63+
// You can process streamed parts here...
64+
bodyChunks.push(chunk);
65+
}).on('end', function() {
66+
var body = Buffer.concat(bodyChunks);
67+
console.log('Ip del Server: ' + body);
68+
global.serverIpAddress = body;
69+
})
70+
});
71+
72+
req.on('error', error => {
73+
console.error(error)
74+
})
75+
76+
req.end()
77+
///Fin Obtenemos IP del server donde se ejecuta la api.
78+
4979
});

models/email.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const fs = require('fs');
2-
const ip = require("ip");
32
const nodemailer = require('nodemailer');
43
const { encriptPassword, getSaltFromAccount } = require("./account");
54

@@ -222,7 +221,7 @@ exports.sendResetAccountPassword = async function (req, res, email, password) {
222221
const encriptedPassword = await encriptPassword(password, salt);
223222

224223
// Hardcodeo la ip por que amazon no funciona bien con esto, asi que hasta que cambiemos de host arreglo esto.
225-
const linkResetPasswordEndpoint = `http://${ip.address()}:1337/api/v1/accounts/resetPassword/${email}/${encriptedPassword}`
224+
const linkResetPasswordEndpoint = `http://${global.serverIpAddress}:1337/api/v1/accounts/resetPassword/${email}/${encriptedPassword}`
226225

227226
htmlContentEmail = htmlContentEmail.replace('VAR_LINK_ENDPOINT_RESET_PASSWORD', linkResetPasswordEndpoint)
228227

0 commit comments

Comments
 (0)