-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (37 loc) · 1.15 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require('express');
const path = require('path');
// Creating server
let app = express();
// set the port of our application
// process.env.PORT lets the port be set by Heroku
const port = process.env.PORT || 3000;
// Trusting proxy IP address details
app.set('trust proxy', true)
// Index route
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/public/index.html'));
});
// User details route
app.get('/me', function(req, res) {
// Data to be returned
let userData = {
'ipaddress': '',
'language': '',
'software': ''
};
// Pulls in user's IP address
userData['ipaddress'] = req.ip;
// Pulls in language
userData['language'] = req.headers["accept-language"].slice(0, req.headers["accept-language"].indexOf(','));
// Stores OS details
userData['software'] = parseOS(req.headers['user-agent']);
res.send(userData);
});
// Parses the user OS data and extracts hardware/software
function parseOS(user) {
let start = user.indexOf('(');
let end = user.indexOf(')')
return userData = user.slice(start + 1, end);
}
// Listening on port
app.listen(port);