Nhận và xác minh webhook nhận dạng trong Node.js và Express. Thêm nhận diện khách truy cập, phát hiện bot và smart signals vào ứng dụng Node.js của bạn trong vài phút.
Thêm SDK vào dự án của bạn với trình quản lý gói ưa thích.
npm install expressyarn add expresspnpm add expressBắt đầu vận hành với thiết lập tối thiểu.
import express from 'express'const app = express()// Capture the raw body so the signature can be verified byte-for-byte.app.use(express.json({ verify: (req, _res, buf) => ((req as any).rawBody = buf) }))// Identification events are pushed here in real timeapp.post('/webhook/tracio', (req, res) => { const event = req.body console.log(event.visitorId, event.bot.result) res.status(200).send('OK')})app.listen(3000)Các mẫu hình sẵn sàng cho production với xử lý lỗi, trạng thái tải và cấu hình nâng cao.
import express from 'express'import crypto from 'crypto'const app = express()app.use(express.json({ verify: (req, _res, buf) => ((req as any).rawBody = buf) }))// Recompute the HMAC-SHA256 over "<t>.<rawBody>" and compare it.function verify(rawBody: Buffer, header: string, secret: string): boolean { const p = Object.fromEntries(header.split(',').map((kv) => kv.split('=') as [string, string])) const signed = Buffer.concat([Buffer.from(`${p.t}.`), rawBody]) const expected = crypto.createHmac('sha256', secret).update(signed).digest('hex') const a = Buffer.from(p.v1, 'hex') const b = Buffer.from(expected, 'hex') return a.length === b.length && crypto.timingSafeEqual(a, b)}app.post('/webhook/tracio', (req, res) => { const sig = req.headers['x-tracio-signature'] as string if (!verify((req as any).rawBody, sig, process.env.TRACIO_WEBHOOK_SECRET!)) { return res.status(401).json({ error: 'Invalid signature' }) } const event = req.body if (event.bot.result === 'bot') { return res.status(200).json({ action: 'blocked', visitorId: event.visitorId }) } if (event.decision.riskScore > 50) { return res.status(200).json({ action: 'review', visitorId: event.visitorId }) } res.status(200).json({ action: 'allow', visitorId: event.visitorId })})app.listen(3000)Tất cả tùy chọn có sẵn để khởi tạo và cấu hình SDK.
publicKeystringPublic key của bạn từ bảng điều khiển — an toàn để đưa lên trình duyệtendpointstringURL endpoint tùy chỉnh cho các triển khai định tuyến qua proxy — URL chỉ định rõ sẽ thắng regionregionstringVùng dữ liệu: us hoặc eutimeoutMsnumberThời gian chờ cho toàn bộ lệnh gọi getResult(), tính bằng mili giâylinkedIdstringID tài khoản nội bộ của bạn cho người dùng đã đăng nhập, để các lượt truy cập chung thiết bị có thể được liên kếttagstringNhãn tự do gắn vào yêu cầu nhận diện, ví dụ checkout hoặc logindebugbooleanGhi vòng đời script và hoạt động mạng ra console của trình duyệtscriptUrlstringGhi đè toàn bộ URL script agent — cho self-hosting hoặc Subresource IntegrityTìm hiểu sâu hơn với tài liệu API đầy đủ, cấu hình webhook và các hướng dẫn nâng cao.
Tài liệu API đầy đủ, hướng dẫn tích hợp và các thực hành tốt nhất.
Gửi sự kiện thời gian thực, schema payload và xác minh chữ ký.
Cấu hình thông báo sự kiện thời gian thực cho mỗi lần nhận diện thiết bị.
Thêm fingerprinting thiết bị vào ứng dụng Node.js của bạn trong chưa đầy 5 phút.