-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 923 Bytes
/
index.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
var express = require('express');
var bodyParser = require('body-parser');
var PORT = process.env.PORT || 5000;
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(function(req, res, next) {
req.userInfo = {};
req.userInfo.ipaddres = req.headers['x-forwarded-for'] ||
req.connection.remoteAddress;
req.userInfo.language = req.headers['accept-language'].split(',')[0] ||
req.acceptedLanguages;
req.userInfo.software = req.headers['user-agent'].split('(')[1].split(')')[0];
next();
});
// app routes
app.get('/', function(req, res) {
res.json({message: 'hello world'});
});
// api routes
apiRouter = express.Router();
apiRouter.get('/whoami', function(req, res) {
res.json(req.userInfo);
});
app.use('/api', apiRouter);
app.listen(PORT, function() {
console.log('running on port ' + PORT);
})
;