简体   繁体   English

如何在Tower.js中获取远程IP地址?

[英]How to get the remote ip address in Tower.js?

I'm creating web service, using Tower.js. 我正在使用Tower.js创建Web服务。 i was able to get the HTTP header and User-agent,but couldn't get a remote ip address. 我能够获取HTTP标头和用户代理,但无法获取远程IP地址。 how to get the remote ip address of requester? 如何获取请求者的远程IP地址?

I tried 我试过了

  1. looked for Tower.Controller class member variable and method (this.request and this.request.app and this.request.headers etc...) 寻找Tower.Controller类的成员变量和方法(this.request和this.request.app和this.request.headers等)
  2. check HTTP headers 检查HTTP头
  3. read the tower-docs (https://github.com/viatropos/tower-docs) 阅读Tower-docs(https://github.com/viatropos/tower-docs)
  4. read the superagent documents (https://github.com/visionmedia/superagent) 阅读超级代理文档(https://github.com/visionmedia/superagent)

If there is lack of information, add. 如果缺少信息,请添加。 thanks. 谢谢。

Thanks for your reply! 感谢您的回复!

I'm checked request object. 我检查了请求对象。 but can't get IP address. 但无法获取IP地址。

installed Tower 0.4.2-3 and Express 3.0.0rc5 but happen runtime error. 安装了Tower 0.4.2-3和Express 3.0.0rc5,但发生运行时错误。 Is supported Express3.0 to Tower.js? 是否支持Express3.0到Tower.js? Or Express 2.x can get remote ip address? 还是Express 2.x可以获取远程IP地址?

Could you please tell me. 你能告诉我吗。

Error message: /var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/mongodb/lib/mongodb/connection/server.js:432 throw err; 错误消息:/var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/mongodb/lib/mongodb/connection/server.js:432 throw err; ^ TypeError: Cannot call method 'apply' of undefined at Tower.Application.Application.reopen.use (/var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/tower/lib/tower-application/server/application.js:115:52) at null. ^ TypeError:无法在Tower.Application.Application.reopen.use(/ var / www / html / melissa / server2 / node_modules / tower / bin / test / node_modules / tower / lib / tower-application中调用未定义的方法'apply' /server/application.js:115:52)为空。 (/var/www/html/melissa/server2/node_modules/tower/bin/test/app/config/server/bootstrap.coffee:9:12) at Tower.Application.Application.reopen.stack (/var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/tower/lib/tower-application/server/application.js:177:16) at Tower.Application.Application.reopen.initialize.initializer (/var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/tower/lib/tower-application/server/application.js:90:19) at Tower.Application.Application.reopen.configureStores (/var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/tower/lib/tower-application/server/application.js:164:27) at _.extend.parallel (/var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/tower/lib/tower-support/shared/shared.js:344:20) at /var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/tower/lib/tower-store/server/mongodb/database.js:52:24 at applyIndexes (/var/www/html/melissa/server2/node_modules/tower/bin/test/ (/var/www/html/melissa/server2/node_modules/tower/bin/test/app/config/server/bootstrap.coffee:9:12)在Tower.Application.Application.reopen.stack(/ var / www / html / melissa / server2 / node_modules / tower / bin / test / node_modules / tower / lib / tower-application / server / application.js:177:16)at Tower.Application.Application.reopen.initialize.initializer(/ var / www.html / melissa / server2 / node_modules / tower / bin / test / node_modules / tower / lib / tower-application / server / application.js:90:19)位于Tower.Application.Application.reopen.configureStores(/ var / www / html / melissa / server2 / node_modules / tower / bin / test / node_modules / tower / lib / tower-application / server / application.js:164:27)位于_.extend.parallel(/ var / www / html / melissa / server2 / node_modules / tower / bin / test / node_modules / tower / lib / tower-support / shared / shared.js:344:20)位于/ var / www / html / melissa / server2 / node_modules / tower / bin / test / node_modules / tower / lib / tower-store / server / mongodb / database.js:52:24 at applyIndexes(/ var / www / html / melissa / server2 / node_modules / tower / bin / test / node_modules/tower/lib/tower-store/server/mongodb/database.js:26:20) at /var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/tower/lib/tower-store/server/mongodb/database.js:50:20 at Db.open (/var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/mongodb/lib/mongodb/db.js:258:14) node_modules / tower / lib / tower-store / server / mongodb / database.js:26:20)位于/ var / www / html / melissa / server2 / node_modules / tower / bin / test / node_modules / tower / lib / tower-在Db.open上存储/服务器/mongodb/database.js:50:20(/var/www/html/melissa/server2/node_modules/tower/bin/test/node_modules/mongodb/lib/mongodb/db.js:258 :14)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM