This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2021-07-10 07:46:29 -07:00
|
|
|
import isHighLoadTime from './overload';
|
|
|
|
|
2021-12-14 06:33:40 -08:00
|
|
|
const USER_AGENT_BOTS = /bot|crawler|baiduspider|80legs|ia_archiver|voyager|curl|wget|yahoo! slurp|mediapartners-google|facebookexternalhit|twitterbot|whatsapp|php|python|mastodon/;
|
2021-06-25 15:51:43 -07:00
|
|
|
const USER_AGENT_BROWSERS = /mozilla|msie|gecko|firefox|edge|opera|safari|netscape|konqueror|android/;
|
|
|
|
|
|
|
|
const isBrowser = (userAgent) => {
|
|
|
|
if (!userAgent) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const isProbablyBot = !!userAgent.toLowerCase().match(USER_AGENT_BOTS);
|
|
|
|
const isProbablyBrowser = !!userAgent.toLowerCase().match(USER_AGENT_BROWSERS);
|
|
|
|
|
2021-12-14 06:33:40 -08:00
|
|
|
return isProbablyBrowser && !isProbablyBot;
|
2021-06-25 15:51:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function(req, res, next) {
|
2021-07-10 07:46:29 -07:00
|
|
|
if (process.env.NODE_ENV === 'production' && !req.url.startsWith('/card/@')) {
|
|
|
|
res.spa = isBrowser(req.headers['user-agent']) || isHighLoadTime(process.env.LOCALE);
|
2021-07-09 11:42:39 -07:00
|
|
|
}
|
|
|
|
next();
|
2021-06-25 15:51:43 -07:00
|
|
|
}
|