Middleware

Node HTTP

A function you call from http.createServer. It does not wrap the response.

Setup

server.ts
import http from 'node:http'
import { node as vector5 } from '@vector5/middleware'

const track = vector5({
  endpoint: 'https://analytics.example.com/api/hit',
  domain: 'example.com',
})

http.createServer((req, res) => {
  track(req, res)
  res.writeHead(200, { 'content-type': 'text/plain' })
  res.end('ok')
}).listen(3000)

Something off? Open an issue · Edit on GitHub