-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
24 lines (24 loc) · 805 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
const express = require('express');
const app = express();
const useragent = require('express-useragent');
const request = require('request');
app.enable('trust proxy');
app.get('/', function(req, res){
res.sendFile('default.html', { root: __dirname + "/client"} );
});
app.get('/api/whoami',function(req,res,next){
let ip =req.ip;
ip = ip.replace(/[a-zA-Z:]+/g,'')
let sw = req.headers['user-agent'];
sw = sw.match(/\(.*\)/g)[0].replace(/[()]/g,'').replace(/ Apple.*/g,'');
let lang = req.headers['accept-language'];
lang = lang.replace(/,.*/,'');
const myObj = {}
myObj.IPAddress = ip;
myObj.Language = lang;
myObj.Software = sw;
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(myObj));
next();
});
app.listen(process.env.PORT || 8080);