mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-17 03:14:46 +00:00
23 lines
641 B
JavaScript
23 lines
641 B
JavaScript
|
import { ModernBrowsers } from '@nuxt/common'
|
||
|
import { matchesUA } from 'browserslist-useragent'
|
||
|
|
||
|
const modernBrowsers = Object.keys(ModernBrowsers)
|
||
|
.map(browser => `${browser} >= ${ModernBrowsers[browser]}`)
|
||
|
|
||
|
const isModernBrowser = (ua) => {
|
||
|
return Boolean(ua) && matchesUA(ua, {
|
||
|
allowHigherVersions: true,
|
||
|
browsers: modernBrowsers
|
||
|
})
|
||
|
}
|
||
|
|
||
|
export default function (req, res, next) {
|
||
|
const { socket = {}, headers } = req
|
||
|
if (socket.isModernBrowser === undefined) {
|
||
|
const ua = headers && headers['user-agent']
|
||
|
socket.isModernBrowser = isModernBrowser(ua)
|
||
|
}
|
||
|
req.isModernBrowser = socket.isModernBrowser
|
||
|
next()
|
||
|
}
|