add browser detection

This commit is contained in:
b1ek 2023-03-19 19:18:34 +10:00
parent adebf02419
commit 6e905308ea
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 3 additions and 9 deletions

View File

@ -2,6 +2,7 @@ const express = require('express');
const router = express.Router();
const minify = require('express-minify');
const browser = require('express-browser-detect');
// custom
router.use(require('./template'));
@ -17,14 +18,6 @@ router.use(minify({
css_match: /.css^/,
js_match: /.js^/
}));
// TODO: Maybe move all regexes into one file? Idk
const legacy_re = /(Firefox\/[0-5]\d{0,1}|Mozilla\/[0-4]|MSIE \d{1,2}\.\d{1,2}|Windows (NT|9\d)|Linux i686|(198\d|199\d|200\d|201[0-6])|Dillo|Naenara|Navscape|Netscape|QtWeb|Prism|Tencent|i(Phone|Pad|Pod)( OS [1-5]|))/g;
router.use((req, res, next) => {
req.legacymode = req.headers['user-agent'].match(legacy_re);
// res.send(req.headers['user-agent']);return;
next();
});
router.use(browser);
module.exports = router;

View File

@ -23,6 +23,7 @@
"easy-crc": "^1.1.0",
"express": "^4.18.2",
"express-async-handler": "^1.2.0",
"express-browser-detect": "^1.0.0",
"express-minify": "^1.0.0",
"express-session": "^1.17.3",
"glob": "^8.1.0",