used object pattern over array
This commit is contained in:
parent
7b6454792b
commit
88097ab151
1 changed files with 9 additions and 11 deletions
|
@ -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/);
|
||||
|
|
Loading…
Reference in a new issue