-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (27 loc) · 811 Bytes
/
app.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
var http = require('http');
var PORT = process.env.PORT || 5000;
//var pg = require('pg');
//var connectionString = "pg://{{db_user}}:{{db_password}}@localhost:5432/{{db_name}}";
var geoip = require('geoip-lite');
http.createServer(function (req, res) {
console.log('%d request received', process.pid);
var ip = req.headers["x-forwarded-for"] || request.connection.remoteAddress;
var geo = geoip.lookup(ip);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Your ip is: ');
res.write(ip);
res.write('\n');
res.write('You live in ');
res.write(JSON.stringify(geo["city"]));
res.end();
}).listen(PORT);
/*
pg.connect(connectionString, function(err, client){
if (err) {
console.log ( err );
} else {
pg.end();
}
});
*/
console.log('%d listening on %d', process.pid, PORT);