@bydefault/vercel
v0.1.4
Published
Bydefault request capture SDK for Vercel and Next.js middleware/proxy.
Downloads
9,850
Maintainers
Readme
@bydefault/vercel
Request capture for Vercel and Next.js proxy.ts / middleware.ts.
The SDK only tracks GET requests for page-like routes. Preflight-style
requests such as HEAD, POST, and other methods are ignored.
By default, /api and /api/* routes are excluded so citation counts reflect
content reads without capturing API endpoints. You can customize this with
exclude.
Install
npm install @bydefault/vercelNext.js proxy.ts
import { Tracker } from '@bydefault/vercel'
import { NextResponse, type NextFetchEvent, type NextRequest } from 'next/server'
const tracker = new Tracker({
token: process.env.BYDEFAULT_INGEST_TOKEN,
})
export function proxy(request: NextRequest, event: NextFetchEvent) {
tracker.track(request, event)
return NextResponse.next()
}Excluding routes
const tracker = new Tracker({
token: process.env.BYDEFAULT_INGEST_TOKEN,
exclude: ['/api', '/admin', /^\/internal\//],
})String excludes match the exact pathname and descendants, so '/api' excludes
both /api and /api/ping. Pass exclude: [] to disable the default /api
exclusion.
Local development
Point endpoint at the Bydefault app:
const tracker = new Tracker({
token: process.env.BYDEFAULT_INGEST_TOKEN,
endpoint: 'http://localhost:3000',
})Payload
The SDK sends a simple request envelope:
type RequestPayload = {
timestamp?: string
method: string
url: string
ip?: string
geo?: {
country?: string
region?: string
city?: string
timezone?: string
latitude?: string
longitude?: string
}
referer?: string
userAgent?: string
accept?: string
acceptLanguage?: string
requestId?: string
}It does not read the request body and does not send the full request header set. The SDK only sends the fields Bydefault needs for request attribution, geo display, and AI-provider detection.
