-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
49 lines (46 loc) · 886 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const spiders = [
/bot/i,
/spider/i,
/facebookexternalhit/i,
/simplepie/i,
/yahooseeker/i,
/embedly/i,
/quora link preview/i,
/outbrain/i,
/vkshare/i,
/monit/i,
/Pingability/i,
/Monitoring/i,
/WinHttpRequest/i,
/Apache-HttpClient/i,
/getprismatic.com/i,
/python-requests/i,
/Twurly/i,
/yandex/i,
/browserproxy/i,
/crawler/i,
/Qwantify/i,
/Yahoo! Slurp/i,
/pinterest/i,
/Tumblr\/14.0.835.186/i,
/Tumblr Agent 14.0/i,
/WhatsApp/i,
/Google-Structured-Data-Testing-Tool/i,
/Google-InspectionTool/i,
/GPTBot/i,
/Applebot/i
]
function isSpider (ua) {
return spiders.some(function (spider) {
return spider.test(ua)
})
}
module.exports = {
isSpider: isSpider,
middleware: function () {
return function (req, res, next) {
req.isSpider = isSpider.bind(undefined, req.get('user-agent'))
next()
}
}
}