Skip to content

Fastify Plugin

@webdecoy/fastify registers the Node SDK as a Fastify plugin. Detection runs on every request, blocked requests get a 403 by default, and the result is attached to req.webdecoy.

Terminal window
npm install @webdecoy/fastify @webdecoy/node
import Fastify from 'fastify';
import webdecoyPlugin from '@webdecoy/fastify';
const fastify = Fastify();
await fastify.register(webdecoyPlugin, {
threshold: 70,
skipPaths: ['/health']
});
fastify.post('/api/checkout', async (req, reply) => {
const { decision, confidence, bot_detected } = req.webdecoy;
if (decision === 'block') {
return reply.code(403).send({ error: 'Request blocked' });
}
if (decision === 'challenge') {
return reply.code(429).send({ error: 'Verification required' });
}
// Process checkout...
});

Extends the core ProtectOptions (threshold, skipLocalAnalysis, metadata) with:

OptionDefaultDescription
getIPrequest.ip (set Fastify’s trustProxy for x-forwarded-for)Custom IP extraction
onBlocked403 ForbiddenCustom handler for blocked requests
onErrorLog and allow (fail open)Custom error handler
skipPathsPaths to skip
rulesLocal rules such as tripwire()

webdecoyCaptchaPlugin mounts the self-hosted captcha endpoints for the Browser Client widget:

import { webdecoyCaptchaPlugin } from '@webdecoy/fastify';
await fastify.register(webdecoyCaptchaPlugin, {
secret: process.env.WEBDECOY_SECRET
});

  • Node SDK — the core API, configuration, and detection response
  • Browser Client — the widget for the captcha endpoints