Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/jsr-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish to JSR

on:
push:
tags:
- 'v*'

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Publish package to JSR
run: npx jsr publish
13 changes: 13 additions & 0 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@codebygarv/express-lens",
"version": "2.5.0",
"description": "Zero-dependency HTTP monitoring, APM metrics, percentile latencies, Prometheus format exporter, slow request profiler, and real-time web dashboard for Express, Fastify, Hono, and Next.js.",
"license": "MIT",
"exports": {
".": "./index.ts",
"./express": "./src/adapters/express.ts",
"./fastify": "./src/adapters/fastify.ts",
"./hono": "./src/adapters/hono.ts",
"./next": "./src/next.ts"
}
}
4 changes: 2 additions & 2 deletions src/adapters/fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import type { ExpressLensOptions } from '../middleware.ts';
/**
* Fastify plugin adapter for Express Lens HTTP monitoring and debugging.
*/
export function fastifyExpressLens(options: ExpressLensOptions = {}) {
export function fastifyExpressLens(options: ExpressLensOptions = {}): (fastify: any) => Promise<void> {
const slowThresholdMs = options.slowThresholdMs != null ? options.slowThresholdMs : 500;
const customRedactList = Array.isArray(options.redactHeaders) ? options.redactHeaders : [];

return async function expressLensPlugin(fastify: any) {
return async function expressLensPlugin(fastify: any): Promise<void> {
const requestTimes = new WeakMap<any, number>();

// 1. Hook into onRequest to record start time
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import type { ExpressLensOptions } from '../middleware.ts';
* Hono & Edge framework adapter for Express Lens HTTP monitoring and debugging.
* Compatible with Hono, Cloudflare Workers, Deno, Bun, and Vercel Edge.
*/
export function honoExpressLens(options: ExpressLensOptions = {}) {
export function honoExpressLens(options: ExpressLensOptions = {}): (c: any, next: () => Promise<void>) => Promise<any> {
const slowThresholdMs = options.slowThresholdMs != null ? options.slowThresholdMs : 500;
const customRedactList = Array.isArray(options.redactHeaders) ? options.redactHeaders : [];

return async function middleware(c: any, next: () => Promise<void>) {
return async function middleware(c: any, next: () => Promise<void>): Promise<any> {
const url = c.req.url || c.req.path || '/';

// 1. Intercept /express-lens dashboard endpoints directly inside Hono
Expand Down
8 changes: 4 additions & 4 deletions src/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import type { ExpressLensOptions } from './middleware.ts';
/**
* Higher-Order Function to wrap Next.js App Router route handlers with HTTP monitoring.
*/
export function withExpressLens(handler: Function, options: ExpressLensOptions = {}) {
export function withExpressLens(handler: Function, options: ExpressLensOptions = {}): (req: Request, context?: any) => Promise<Response> {
const slowThresholdMs = options.slowThresholdMs != null ? options.slowThresholdMs : 500;
const customRedactList = Array.isArray(options.redactHeaders) ? options.redactHeaders : [];

return async function expressLensNextHandler(req: Request, context?: any) {
return async function expressLensNextHandler(req: Request, context?: any): Promise<Response> {
const startTime = globalThis.performance ? globalThis.performance.now() : Date.now();
const url = req.url || '/';
const method = req.method || 'GET';
Expand Down Expand Up @@ -102,8 +102,8 @@ export function withExpressLens(handler: Function, options: ExpressLensOptions =
* Route handler for exposing the Express Lens dashboard in Next.js catch-all route.
* Usage: export const GET = dashboardRoute(); inside app/api/express-lens/[[...route]]/route.ts
*/
export function dashboardRoute() {
return async function handleNextDashboard(req: Request) {
export function dashboardRoute(): (req: Request) => Promise<Response> {
return async function handleNextDashboard(req: Request): Promise<Response> {
const url = req.url || '';
if (url.includes('/metrics-json')) {
return Response.json(store.getMetrics());
Expand Down
Loading