Skip to content

Commit 5669bc7

Browse files
authored
Updating docs (#12)
* chore: update installation commands from npm to bun in middleware documentation * feat: add Prometheus middleware functions for enhanced metrics integration
1 parent a656d29 commit 5669bc7

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

lib/middleware/README.md

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Install only the dependencies you need:
1010

1111
```bash
1212
# For JWT Authentication middleware
13-
npm install jose
13+
bun install jose
1414

1515
# For Logger middleware
16-
npm install pino
16+
bun install pino
1717

1818
# For Prometheus Metrics middleware
19-
npm install prom-client
19+
bun install prom-client
2020
```
2121

2222
**Benefits of Lazy Loading:**
@@ -91,6 +91,9 @@ const {
9191
createJWTAuth,
9292
createLogger,
9393
createRateLimit,
94+
createPrometheusMiddleware,
95+
createMetricsHandler,
96+
createPrometheusIntegration,
9497
} = require('0http-bun/lib/middleware')
9598
```
9699

@@ -104,6 +107,9 @@ import {
104107
createJWTAuth,
105108
createLogger,
106109
createRateLimit,
110+
createPrometheusMiddleware,
111+
createMetricsHandler,
112+
createPrometheusIntegration,
107113
} from '0http-bun/lib/middleware'
108114

109115
// Import types
@@ -224,7 +230,7 @@ router.use(createCORS(corsOptions))
224230
225231
JSON Web Token authentication and authorization middleware with support for static secrets, JWKS endpoints, and API key authentication.
226232
227-
> 📦 **Required dependency**: `npm install jose`
233+
> 📦 **Required dependency**: `bun install jose`
228234
229235
#### Basic JWT with Static Secret
230236
@@ -477,7 +483,7 @@ router.get('/api/profile', (req) => {
477483
478484
Request logging middleware with customizable output formats.
479485
480-
> 📦 **Required dependency for structured logging**: `npm install pino`
486+
> 📦 **Required dependency for structured logging**: `bun install pino`
481487
> ✅ **Simple logger** (`simpleLogger`) has no dependencies - uses `console.log`
482488
483489
```javascript
@@ -542,10 +548,14 @@ router.use(createLogger(loggerOptions))
542548
543549
Comprehensive Prometheus metrics integration for monitoring and observability with built-in security and performance optimizations.
544550
545-
> 📦 **Required dependency**: `npm install prom-client`
551+
> 📦 **Required dependency**: `bun install prom-client`
546552
547553
```javascript
548-
import {createPrometheusIntegration} from '0http-bun/lib/middleware/prometheus'
554+
const {
555+
createPrometheusMiddleware,
556+
createMetricsHandler,
557+
createPrometheusIntegration,
558+
} = require('0http-bun/lib/middleware')
549559

550560
// Simple setup with default metrics
551561
const prometheus = createPrometheusIntegration()
@@ -568,6 +578,12 @@ The Prometheus middleware automatically collects:
568578
#### Advanced Configuration
569579
570580
```javascript
581+
const {
582+
createPrometheusMiddleware,
583+
createMetricsHandler,
584+
createPrometheusIntegration,
585+
} = require('0http-bun/lib/middleware')
586+
571587
const prometheus = createPrometheusIntegration({
572588
// Control default Node.js metrics collection
573589
collectDefaultMetrics: true,
@@ -602,6 +618,12 @@ const prometheus = createPrometheusIntegration({
602618
#### Custom Business Metrics
603619
604620
```javascript
621+
const {
622+
createPrometheusIntegration,
623+
} = require('0http-bun/lib/middleware')
624+
625+
// Get the prometheus client from the integration
626+
const prometheus = createPrometheusIntegration()
605627
const {promClient} = prometheus
606628

607629
// Create custom metrics
@@ -644,6 +666,8 @@ router.post('/orders', async (req) => {
644666
#### Metrics Endpoint Options
645667
646668
```javascript
669+
const {createMetricsHandler} = require('0http-bun/lib/middleware')
670+
647671
// Custom metrics endpoint
648672
const metricsHandler = createMetricsHandler({
649673
endpoint: '/custom-metrics', // Default: '/metrics'
@@ -1029,8 +1053,8 @@ Apply middleware only to specific paths:
10291053
10301054
```typescript
10311055
// API-only middleware
1032-
router.use('/api/*', jwtAuth({secret: 'api-secret'}))
1033-
router.use('/api/*', rateLimit({max: 1000}))
1056+
router.use('/api/*', createJWTAuth({secret: 'api-secret'}))
1057+
router.use('/api/*', createRateLimit({max: 1000}))
10341058

10351059
// Admin-only middleware
10361060
router.use('/admin/*', adminAuthMiddleware)
@@ -1112,14 +1136,14 @@ For your convenience, here's a quick reference of which dependencies you need to
11121136
| **CORS** | ✅ None | Built-in |
11131137
| **Rate Limiting** | ✅ None | Built-in |
11141138
| **Logger** (simple) | ✅ None | Built-in |
1115-
| **Logger** (structured) | 📦 `pino` | `npm install pino` |
1116-
| **JWT Authentication** | 📦 `jose` | `npm install jose` |
1117-
| **Prometheus Metrics** | 📦 `prom-client` | `npm install prom-client` |
1139+
| **Logger** (structured) | 📦 `pino` | `bun install pino` |
1140+
| **JWT Authentication** | 📦 `jose` | `bun install jose` |
1141+
| **Prometheus Metrics** | 📦 `prom-client` | `bun install prom-client` |
11181142
11191143
**Install all optional dependencies at once:**
11201144
11211145
```bash
1122-
npm install pino jose prom-client
1146+
bun install pino jose prom-client
11231147
```
11241148
11251149
This middleware stack provides a solid foundation for most web applications with security, logging, and performance features built-in.

0 commit comments

Comments
 (0)