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

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)

Install

pnpm i @tinyhttp/bot-detector

Version

1.3.11

Source

@tinyhttp/bot-detector