Code Monkey home page Code Monkey logo

Comments (11)

CITGuru avatar CITGuru commented on July 19, 2024

What kind of error occured?

from express-ip.

CITGuru avatar CITGuru commented on July 19, 2024

Fixed

from express-ip.

fcolella avatar fcolella commented on July 19, 2024

Hi guys! I'm getting that error as well, how did you fix it?
Thanks!

just doing this (relevant stuff):

const expressip = require('express-ip');
app.use(expressip().getIpInfoMiddleware); // GEO

app.get('/geo-test', function (req, res) {
res.send(req.ipInfo);
});

from express-ip.

fcolella avatar fcolella commented on July 19, 2024

Nevermind, I have the latest version (1.0.3) but it doesn't have this code:

if ((ip === '127.0.0.1' || ip === '::1')) { return {error:"This won't work on localhost"} }

it has this:

if ((ip === '127.0.0.1')) { return {error:"This won't work on localhost"} }

And my localhost was returning ::1
Also not working when IP data comes with multiple IPs like so "200.x.x.x, 10.x.x.x, 10.x.x.x"
Maybe reverse proxy issue?
Thanks!

from express-ip.

CITGuru avatar CITGuru commented on July 19, 2024

Hmmnn. I will add support for that. Thanks raising this up

from express-ip.

muhaimincs avatar muhaimincs commented on July 19, 2024

is it solve? I'm also facing the same thing

Nevermind, I have the latest version (1.0.3) but it doesn't have this code:

if ((ip === '127.0.0.1' || ip === '::1')) { return {error:"This won't work on localhost"} }

it has this:

if ((ip === '127.0.0.1')) { return {error:"This won't work on localhost"} }

And my localhost was returning ::1
Also not working when IP data comes with multiple IPs like so "200.x.x.x, 10.x.x.x, 10.x.x.x"
Maybe reverse proxy issue?
Thanks!

from express-ip.

mikestecker avatar mikestecker commented on July 19, 2024

I'm having this issue also. I've tried testing using ngrok and console.log my info, but only receive { error: 'Error occured while trying to process the information' }

my code is simply as follows:

server.express.use(expressip().getIpInfoMiddleware);
server.express.use((req, res, next) => {
  const userIp = req.ipInfo;
  if (userIp) {
    console.log(userIp);
    req.userIp = userIp;
  }
  next();
});

from express-ip.

CITGuru avatar CITGuru commented on July 19, 2024

@mikestecker I think there's an issue with the ngrok header response. I came across that back ago.

from express-ip.

tamirDavidoff avatar tamirDavidoff commented on July 19, 2024

Hello everyone, I have a similar issue.
This is the code -
app.get("/ipInfo", function(req,res){
var myEnv = req.connection.remoteAddress;
if (myEnv == "::ffff:127.0.0.1") {
res.send("does this work? " + req.ipInfo);
} else {
res.send(req.ipInfo);
}

});

It works on local and says - This cannot work on a localhost.
It works on NGROK and returns the ipInfo object with all the information

However, on a live server (heroku) It says {"error":"Error occured while trying to process the information"}

please assist me,

Thanks!

from express-ip.

2M4U avatar 2M4U commented on July 19, 2024

express-ip doesn't seem to like x-forwarded-ip headers:

Reproducing the steps:
Using Nginx + NodeJS + Cloudflare.

Example:

{
  ip: '1.3.3.7,1.1.1.1',
  error: 'Error occured while trying to process the information'
}

from express-ip.

seba-wetzel avatar seba-wetzel commented on July 19, 2024

Here is a solution for the issue when we have a proxy

  const getIpInfoMiddleware = function(req, res, next) {
    const xForwardedFor = (req.headers["x-forwarded-for"] || "").
        replace(/:\d+$/, "");
    let ip = xForwardedFor || req.connection.remoteAddress;
    ip = ip.split(",")[0];  //this line select the first ip (if severals)
    req.ipInfo = {ip, ...getIpInfo(ip)};
    next();
  };

from express-ip.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.