-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
16 lines (15 loc) · 815 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var http = require('http');
var buildHTML = require('./buildHTML');
http.createServer(function (request, response) {
var ip = request.headers['x-forwarded-for'] || request.connection.remoteAddress;
ip = ip.substr(0, 7) === '::ffff:' ? ip.substr(7) : ip;
//returned is a string; convert it to array and select the first item
var languageArray = request.headers["accept-language"].split(',');
var language = languageArray[0];
//returned is a string; with match returned is array of matches
var OSArray = request.headers['user-agent'].match(/\((.*?)\)/);
//select the first item/the whole string that matches and remove ()
var OS = OSArray[0].substr(1, OSArray[0].length - 2);
var html = buildHTML(ip, language, OS);
response.end(html);
}).listen(process.env.PORT || 8080);