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