From 88097ab151924461da145e5f53c7e56ea3c82c33 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 27 Jun 2018 09:45:09 -0700 Subject: [PATCH] used object pattern over array --- .../assets/utils/determineRequestType.js | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/server/controllers/assets/utils/determineRequestType.js b/server/controllers/assets/utils/determineRequestType.js index c268380f..56bfc1ca 100644 --- a/server/controllers/assets/utils/determineRequestType.js +++ b/server/controllers/assets/utils/determineRequestType.js @@ -2,19 +2,17 @@ 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); - return true; - } + const socialBotList = { + 'facebookexternalhit': 1, + 'Twitterbot' : 1, + }; + if (socialBotList[userAgent]) { + logger.debug('headers on request matched a social bot.'); + return true; + } else { + return false; } - return false; } function clientAcceptsHtml ({accept}) {