@centinel/vercel
v1.0.1
Published
Package designed to add Centinel Analytica functionality to Vercel edge middleware
Maintainers
Readme
Centinel Analytica Vercel Middleware
A lightweight Vercel middleware package for integrating Centinel Analytica bot protection into your Next.js applications.
Installation
npm install @centinel/vercelQuick Start
Middleware Setup
Create a middleware.ts file in your project root:
import { createCentinelMiddleware } from '@centinel/vercel';
export default createCentinelMiddleware({
siteKey: process.env.CENTINEL_SITE_KEY!,
secretKey: process.env.CENTINEL_SECRET_KEY!
});
export const config = {
matcher: ['/api/:path*', '/dashboard/:path*']
};Or use environment variables directly:
import { createCentinelMiddlewareFromEnv } from '@centinel/vercel';
export default createCentinelMiddlewareFromEnv();
export const config = {
matcher: ['/api/:path*', '/dashboard/:path*']
};API Route Setup
Create an API route for form validation:
// app/api/validate-form/route.ts
import { createFormValidator } from '@centinel/vercel';
const validator = createFormValidator({
siteKey: process.env.CENTINEL_SITE_KEY!,
secretKey: process.env.CENTINEL_SECRET_KEY!
});
export const POST = validator.validateForm;Or using environment variables:
// app/api/validate-form/route.ts
import { createFormValidatorFromEnv } from '@centinel/vercel';
const { validateForm } = createFormValidatorFromEnv();
export const POST = validateForm;Environment Variables
Set these environment variables in your .env.local file:
CENTINEL_SITE_KEY=your_site_key_here
CENTINEL_SECRET_KEY=your_secret_key_hereHow It Works
The middleware validates requests in parallel with your application for optimal performance:
- Validation runs alongside your origin request
- Fast response without waiting for validation
- Smart override if validation requires blocking/redirecting
API Response Format
The validation API returns responses in this format:
{
success: boolean;
decision: 'allow' | 'block' | 'redirect' | 'not_matched';
redirect_url?: string;
cookies?: Array<{
name: string;
value: string;
path?: string;
domain?: string;
}>;
}Configuration
Middleware Matcher
Configure which routes the middleware should protect:
export const config = {
matcher: [
'/api/:path*', // Protect all API routes
'/dashboard/:path*', // Protect dashboard routes
'/admin/:path*' // Protect admin routes
]
};