@tinyhttp/bot-detector

npm (scoped) npm

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 properties, isBot and botName.

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'

app.use(botDetector())

const app = new App<any, RequestWithBotDetector, Response>()

app.use((req, res) => {
  res.send(req.isBot ? `Bot detected 🤖: ${req.botName}` : 'Hello World!')
})

app.listen(3000)

License

MIT © v1rtl

Install

pnpm i @tinyhttp/bot-detector

Version

0.5.36

Source

packages/bot-detector