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.
Zaimki/server/no-ssr.js

23 lines
980 B
JavaScript
Raw Normal View History

2021-07-10 07:46:29 -07:00
import isHighLoadTime from './overload';
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);
}
next();
}