How to get the user IP address in Meteor server?

前端 未结 6 810
情书的邮戳
情书的邮戳 2020-11-30 03:03

I would like to get the user IP address in my meteor application, on the server side, so that I can log the IP address with a bunch of things (for example: non-registered us

6条回答
  •  死守一世寂寞
    2020-11-30 03:57

    Similar to the TimDog answer but works with newer versions of Meteor:

    var Fiber = Npm.require('fibers');
    
    __meteor_bootstrap__.app
      .use(function(req, res, next) {
        Fiber(function () {
          console.info(req.connection.remoteAddress);
          next();
        }).run();
      });
    

    This needs to be in your top-level server code (not in Meteor.startup)

提交回复
热议问题