-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathexample.js
41 lines (36 loc) · 911 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var http = require('http');
var cf = require('./node_CloudFlare.js');
// Configure our HTTP server to respond with the users IP address.
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, {
'Content-Type': 'image/x-icon'
});
res.end();
return;
}
res.writeHead(200, {
"Content-Type": "text/plain"
});
var ip_address = (req.connection.remoteAddress ? req.connection.remoteAddress : req.remoteAddress);
res.end('Your IP: ' + ip_address);
});
cf.load(function (error, fs_error) //Loads the ranges and then starts the webserver.
{
if (fs_error)
{
throw new Error(fs_error);
}
server.listen(8880);
console.log('Server running.');
});