Explorar o código

Fixed not getting ip address right

Pouria Ezzati %!s(int64=8) %!d(string=hai) anos
pai
achega
e225b031b4

+ 1 - 1
server/controllers/authController.js

@@ -67,7 +67,7 @@ exports.recaptcha = async (req, res, next) => {
       params: {
         secret: config.RECAPTCHA_SECRET_KEY,
         response: req.body.reCaptchaToken,
-        remoteip: req.ip,
+        remoteip: req.realIp,
       },
     });
     if (!isReCaptchaValid.data.success) {

+ 1 - 1
server/controllers/urlController.js

@@ -83,7 +83,7 @@ exports.goToUrl = async (req, res, next) => {
   const [browser = 'Other'] = browsersList.filter(filterInBrowser(agent));
   const [os = 'Other'] = osList.filter(filterInOs(agent));
   const referrer = req.header('Referer') && URL.parse(req.header('Referer')).hostname;
-  const location = geoip.lookup(req.ip);
+  const location = geoip.lookup(req.realIp);
   const country = location && location.country;
   const urls = await findUrl({ id, domain });
   if (!urls && !urls.length) return next();

+ 1 - 1
server/server.js

@@ -59,7 +59,7 @@ app.prepare().then(() => {
   server.use(express.static('static'));
 
   server.use((req, res, next) => {
-    req.ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || '';
+    req.realIp = req.headers['x-real-ip'] || req.connection.remoteAddress || '';
     return next();
   });