2013-05-05 71 views
-1

我正在使用Meteor开发一个简单的博客应用程序。但是,用户将被允许匿名发布。我想记录发件人的IP地址以及他们的博客文章。如何将用户IP地址记录到数据库?

我找不到任何方法来访问IP地址。我怎样才能做到这一点?

+2

可能重复[如何获得流星服务器的用户的IP地址?(http://stackoverflow.com/questions/14843232/how-to-get-the-user-ip-address-in - 流星服务器) – 2013-05-05 16:54:54

回答

0
if (Meteor.isServer) { 
    var app = __meteor_bootstrap__.app, 
     Fiber = Npm.require('fibers'), 
     headers = {}; 

     app.use(function(req, res, next) {Fiber(function() { 

      headers.remoteAddress = req.connection.remoteAddress; 
      console.info(req.connection.remoteAddress); 

      console.info(res.socket._peername); 
      next(); 
     }).run(); 
     }); 
} 
+0

是的,所以?... – hakan 2013-08-23 10:33:48

相关问题