https://github.com/gavinning/express-detector
Express格式化ua中间件,检查Client是PC或者Mobile
https://github.com/gavinning/express-detector
Last synced: over 1 year ago
JSON representation
Express格式化ua中间件,检查Client是PC或者Mobile
- Host: GitHub
- URL: https://github.com/gavinning/express-detector
- Owner: gavinning
- Created: 2016-08-26T08:47:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-26T09:07:26.000Z (almost 10 years ago)
- Last Synced: 2025-02-01T12:46:31.721Z (over 1 year ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
express-detector
---
### Install
```sh
npm i express-detector --save
```
### Usage
```js
var detector = require('express-detector');
app.use(detector());
```
```js
router.all('*', (req, res) => {
console.log(req.env)
// 是否跳转到移动端
req.env.isMobile ? res.redirect('http://m.domain.com') : next();
})
```
console.log( req.env ) =>
```js
{
device: {
name: 'iphone',
version: -1,
fullVersion: '-1',
iphone: -1
},
os: {
name: 'ios',
version: 9.1,
fullVersion: '9.1',
ios: 9.1
},
engine: {
name: 'webkit',
version: 601.1,
fullVersion: '601.1.46',
mode: 601.1,
fullMode: '601.1.46',
compatible: false,
webkit: 601.1
},
browser: {
name: 'safari',
version: 9,
fullVersion: '9.0',
mode: 9,
fullMode: '9.0',
compatible: false,
safari: 9
},
isPC: false,
isMobile: true
}
```