-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathindex.js
50 lines (50 loc) · 1.73 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
*
* @revision $Id: index.js 2012-03-24 16:21:10 Aleksey $
* @created 2012-03-24 16:21:10
* @category Express Helpers
* @package express-useragent
* @version 1.0.15
* @copyright Copyright (c) 2009-2020 - All rights reserved.
* @license MIT License
* @author Aleksejs Gordejevs IK <[email protected]>
* @link http://www.gordejev.lv
*
*/
var usrg = require('./lib/express-useragent');
var UserAgent = usrg.UserAgent;
module.exports = new UserAgent();
module.exports.UserAgent = UserAgent;
module.exports.express = function () {
return function (req, res, next) {
var source = req.headers['user-agent'] || '';
if (req.headers['x-ucbrowser-ua']) { //special case of UC Browser
source = req.headers['x-ucbrowser-ua'];
}
var ua = new UserAgent();
if (typeof source === 'undefined') {
source = "unknown";
}
ua.Agent.source = source.replace(/^\s*/, '').replace(/\s*$/, '');
ua.Agent.os = ua.getOS(ua.Agent.source);
ua.Agent.platform = ua.getPlatform(ua.Agent.source);
ua.Agent.browser = ua.getBrowser(ua.Agent.source);
ua.Agent.version = ua.getBrowserVersion(ua.Agent.source);
ua.testNginxGeoIP(req.headers);
ua.testBot();
ua.testMobile();
ua.testAndroidTablet();
ua.testTablet();
ua.testCompatibilityMode();
ua.testSilk();
ua.testKindleFire();
ua.testWechat();
req.useragent = ua.Agent;
if ('function' === typeof res.locals) {
res.locals({useragent: ua.Agent});
} else {
res.locals.useragent = ua.Agent;
}
next();
};
};