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

22 lines
863 B
JavaScript
Raw Normal View History

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/;
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;
}
export default function(req, res, next) {
2022-02-25 08:35:03 -08:00
if (process.env.NODE_ENV === 'production' && !req.url.startsWith('/card/@')) {
res.spa = isBrowser(req.headers['user-agent']) || isHighLoadTime(process.env.LOCALE);
}
next();
}