README
@tinyhttp/bot-detector
Detect bots among users in your tinyhttp app. This middlewares is based on isbot.
Note that it doesn't differentiate "good" and "bad" bots, it only shows if a request comes from a bot (e.g. crawler) or from a real human.
Install
pnpm i @tinyhttp/bot-detector
API
botDetector()(req, res)
This middleware adds 2 new getters, isBot
and botName
.
isBot
is a boolean which shows if the request is made by a botbotName
is a string that shows the bot name in caseisBot
is true.
Both getters are lazy and will not be calculated until needed
Example
import { App } from '@tinyhttp/app'
import type { Response } from '@tinyhttp/app'
import { botDetector } from '@tinyhttp/bot-detector'
import type { RequestWithBotDetector } from '@tinyhttp/bot-detector'
new App<any, RequestWithBotDetector, Response>()
.use(botDetector())
.use((req, res) => {
res.send(req.isBot ? `Bot detected 🤖: ${req.botName}` : 'Hello World!')
})
.listen(3000)