Skip to content

Backend

Reference backend implementations live in the server/ directory. They are not published packages — copy the code you need into your own backend project.

DirectoryFrameworkPortDescription
server/nodeExpress 53001Node.js backend demo
server/javaSpring Boot 38080Java backend demo
server/goGin8082Go backend demo

Quick Start (Node.js Demo)

bash
cd server/node
pnpm install
pnpm dev

Server runs at http://localhost:3001. See each server directory's README for details.

API Endpoints

MethodEndpointDescription
GET/api/captchaGenerate captcha image
POST/api/captcha/verifyVerify captcha
GET/api/healthHealth check
GET/api/infoServer info

Generate Captcha

GET /api/captcha?type=slider&width=300&height=170

ParameterTypeDefaultDescription
typestringsliderCaptcha type: slider or click
widthnumber300Image width
heightnumber170Image height
precisionnumber5Verification precision
clickCountnumber3Click count (for click type)

Response (slider):

json
{
  "success": true,
  "data": {
    "captchaId": "uuid-string",
    "type": "slider",
    "bgImage": "data:image/png;base64,...",
    "sliderImage": "data:image/png;base64,...",
    "sliderY": 42,
    "width": 300,
    "height": 170,
    "expiresAt": 1700000000000
  }
}

Response (click) includes clickTexts and clickCharImages instead of sliderImage/sliderY.

Verify Captcha

POST /api/captcha/verify

Request body:

json
{
  "captchaId": "uuid-string",
  "type": "slider",
  "target": [123]
}

Response:

json
{
  "success": true,
  "message": "Verification successful",
  "data": { "verifiedAt": 1700000000000 }
}

Security Endpoints

MethodEndpointDescription
GET/api/security/status/:ipGet IP security status
GET/api/security/blacklistGet blacklist entries
POST/api/security/blacklistAdd IP to blacklist
DELETE/api/security/blacklist/:ipRemove IP from blacklist

Environment Variables

VariableDefaultDescription
PORT3001 (Node) / 8080 (Java) / 8082 (Go)Server port
HOSTlocalhostServer host
SECRET_KEYcaptcha-pro-secret-keyAES-GCM encryption key
EXPIRE_TIME60000Captcha expire time (ms)
TIMESTAMP_TOLERANCE60000Timestamp tolerance (ms)

Frontend Integration

javascript
import { SliderCaptcha } from '@captcha-pro/core'

const captcha = new SliderCaptcha({
  el: '#captcha',
  verifyMode: 'backend',
  backendVerify: {
    getCaptcha: 'http://localhost:3001/api/captcha?type=slider',
    verify: 'http://localhost:3001/api/captcha/verify'
  },
  onSuccess: () => console.log('Backend verification passed!')
})

Per-Server Guides

Released under the MIT License.