Permalink
Browse files

Improved example as decribed in nodejs/node-v0.x-archive#3323

  • Loading branch information...
1 parent a0d8618 commit 73b856b1e270527900917b77bd6791662c8e6a07 @keverw committed May 26, 2012
Showing with 10 additions and 9 deletions.
  1. +9 −8 example.js
  2. +1 −1 readme.md
View
17 example.js
@@ -5,6 +5,14 @@ var cf = require('./node_CloudFlare.js');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (req, res)
{
+ if (cf.check(req)) //CF
+ {
+ req.real_ip = cf.get(req);
+ req.connection.__defineGetter__('remoteAddress', function() {
+ return req.real_ip;
+ });
+ }
+
if (req.url === '/favicon.ico')
{ //Thank's https://gist.github.com/763822
res.writeHead(200, {
@@ -19,14 +27,7 @@ var server = http.createServer(function (req, res)
});
var ip_address = (req.connection.remoteAddress ? req.connection.remoteAddress : req.remoteAddress);
- if (cf.check(req)) //CF
- {
- res.end('CF IP: ' + ip_address + '\nYour IP: ' + cf.get(req));
- }
- else //not CF
- {
- res.end(ip_address);
- }
+ res.end('Your IP: ' + ip_address);
});
cf.load(function (error, fs_error)
View
2 readme.md
@@ -38,7 +38,7 @@ var ip_address = (req.connection.remoteAddress ? req.connection.remoteAddress :
}
```
-Check out `example.js` for a full working demo
+Check out `example.js` for a another working exmaple that overrides the `req.connection.remoteAddress` getter.
##Dependencies##
Range Check - [https://github.com/keverw/range_check](https://github.com/keverw/range_check)

0 comments on commit 73b856b

Please sign in to comment.