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-06-25 15:51:43 -07:00
|
|
|
const USER_AGENT_BOTS = /bot|crawler|baiduspider|80legs|ia_archiver|voyager|curl|wget|yahoo! slurp|mediapartners-google|facebookexternalhit|twitterbot|whatsapp|php|python/;
|
|
|
|
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);
|
|
|
|
|
|
|
|
return isProbablyBrowser || !isProbablyBot;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function(req, res, next) {
|
2021-07-10 07:46:29 -07:00
|
|
|
if (process.env.NODE_ENV === 'production' && !req.url.startsWith('/card/@')) {
|
2021-07-10 09:31:22 -07:00
|
|
|
console.log(req.url, isBrowser(req.headers['user-agent']), isHighLoadTime(process.env.LOCALE)); // TODO remove later
|
2021-07-10 07:46:29 -07:00
|
|
|
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
|
|
|
}
|