-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
30 lines (19 loc) · 767 Bytes
/
server.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
var express = require('express');
var app = express();
app.get("/", function (request, response) {
response.sendFile(__dirname + '/views/index.html');
});
app.set('trust proxy', true);
app.get("/api/whoami", function (request, response) {
var data = {};
data['ip'] = request.ips[0];
var foundSystem = request.headers['user-agent'].match(/\(([^)]*?)\)/);
data['system'] = (foundSystem != null) ? foundSystem[1] : null;
var foundLanguages = request.acceptsLanguages();
data['language'] = (foundLanguages.length > 0) ? foundLanguages[0] : null;
response.send(data);
});
// listen for requests :)
var listener = app.listen(process.env.PORT, function () {
console.log('Your app is listening on port ' + listener.address().port);
});