used object pattern over array

This commit is contained in:
bill bittner 2018-06-27 09:45:09 -07:00
parent 7b6454792b
commit 88097ab151

View file

@ -2,20 +2,18 @@ const logger = require('winston');
const { EMBED, BROWSER, SOCIAL } = require('../constants/request_types.js');
function headersMatchesSocialBotList (headers) {
const socialBotList = [
'facebookexternalhit',
'Twitterbot',
];
const userAgent = headers['user-agent'];
for (let i = 0; i < socialBotList.length; i++) {
const socialBot = socialBotList[i];
if (userAgent.indexOf(socialBot) >= 0) {
logger.debug('headers on request matched this bot:', socialBot);
const socialBotList = {
'facebookexternalhit': 1,
'Twitterbot' : 1,
};
if (socialBotList[userAgent]) {
logger.debug('headers on request matched a social bot.');
return true;
}
}
} else {
return false;
}
}
function clientAcceptsHtml ({accept}) {
return accept && accept.match(/text\/html/);