@@ -10,13 +10,13 @@ Install only the dependencies you need:
10
10
11
11
``` bash
12
12
# For JWT Authentication middleware
13
- npm install jose
13
+ bun install jose
14
14
15
15
# For Logger middleware
16
- npm install pino
16
+ bun install pino
17
17
18
18
# For Prometheus Metrics middleware
19
- npm install prom-client
19
+ bun install prom-client
20
20
```
21
21
22
22
** Benefits of Lazy Loading:**
@@ -91,6 +91,9 @@ const {
91
91
createJWTAuth ,
92
92
createLogger ,
93
93
createRateLimit ,
94
+ createPrometheusMiddleware ,
95
+ createMetricsHandler ,
96
+ createPrometheusIntegration ,
94
97
} = require (' 0http-bun/lib/middleware' )
95
98
```
96
99
@@ -104,6 +107,9 @@ import {
104
107
createJWTAuth ,
105
108
createLogger ,
106
109
createRateLimit ,
110
+ createPrometheusMiddleware ,
111
+ createMetricsHandler ,
112
+ createPrometheusIntegration ,
107
113
} from ' 0http-bun/lib/middleware'
108
114
109
115
// Import types
@@ -224,7 +230,7 @@ router.use(createCORS(corsOptions))
224
230
225
231
JSON Web Token authentication and authorization middleware with support for static secrets, JWKS endpoints, and API key authentication.
226
232
227
- > 📦 **Required dependency**: ` npm install jose`
233
+ > 📦 **Required dependency**: ` bun install jose`
228
234
229
235
#### Basic JWT with Static Secret
230
236
@@ -477,7 +483,7 @@ router.get('/api/profile', (req) => {
477
483
478
484
Request logging middleware with customizable output formats.
479
485
480
- > 📦 **Required dependency for structured logging**: ` npm install pino`
486
+ > 📦 **Required dependency for structured logging**: ` bun install pino`
481
487
> ✅ **Simple logger** (` simpleLogger` ) has no dependencies - uses ` console .log `
482
488
483
489
` ` ` javascript
@@ -542,10 +548,14 @@ router.use(createLogger(loggerOptions))
542
548
543
549
Comprehensive Prometheus metrics integration for monitoring and observability with built-in security and performance optimizations.
544
550
545
- > 📦 **Required dependency**: ` npm install prom- client`
551
+ > 📦 **Required dependency**: ` bun install prom- client`
546
552
547
553
` ` ` javascript
548
- import {createPrometheusIntegration } from ' 0http-bun/lib/middleware/prometheus'
554
+ const {
555
+ createPrometheusMiddleware ,
556
+ createMetricsHandler ,
557
+ createPrometheusIntegration ,
558
+ } = require (' 0http-bun/lib/middleware' )
549
559
550
560
// Simple setup with default metrics
551
561
const prometheus = createPrometheusIntegration ()
@@ -568,6 +578,12 @@ The Prometheus middleware automatically collects:
568
578
#### Advanced Configuration
569
579
570
580
` ` ` javascript
581
+ const {
582
+ createPrometheusMiddleware ,
583
+ createMetricsHandler ,
584
+ createPrometheusIntegration ,
585
+ } = require (' 0http-bun/lib/middleware' )
586
+
571
587
const prometheus = createPrometheusIntegration ({
572
588
// Control default Node.js metrics collection
573
589
collectDefaultMetrics: true ,
@@ -602,6 +618,12 @@ const prometheus = createPrometheusIntegration({
602
618
#### Custom Business Metrics
603
619
604
620
` ` ` javascript
621
+ const {
622
+ createPrometheusIntegration ,
623
+ } = require (' 0http-bun/lib/middleware' )
624
+
625
+ // Get the prometheus client from the integration
626
+ const prometheus = createPrometheusIntegration ()
605
627
const {promClient } = prometheus
606
628
607
629
// Create custom metrics
@@ -644,6 +666,8 @@ router.post('/orders', async (req) => {
644
666
#### Metrics Endpoint Options
645
667
646
668
` ` ` javascript
669
+ const {createMetricsHandler } = require (' 0http-bun/lib/middleware' )
670
+
647
671
// Custom metrics endpoint
648
672
const metricsHandler = createMetricsHandler ({
649
673
endpoint: ' /custom-metrics' , // Default: '/metrics'
@@ -1029,8 +1053,8 @@ Apply middleware only to specific paths:
1029
1053
1030
1054
` ` ` typescript
1031
1055
// 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 }))
1034
1058
1035
1059
// Admin-only middleware
1036
1060
router .use (' /admin/*' , adminAuthMiddleware)
@@ -1112,14 +1136,14 @@ For your convenience, here's a quick reference of which dependencies you need to
1112
1136
| **CORS** | ✅ None | Built-in |
1113
1137
| **Rate Limiting** | ✅ None | Built-in |
1114
1138
| **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` |
1118
1142
1119
1143
**Install all optional dependencies at once:**
1120
1144
1121
1145
` ` ` bash
1122
- npm install pino jose prom- client
1146
+ bun install pino jose prom- client
1123
1147
` ` `
1124
1148
1125
1149
This middleware stack provides a solid foundation for most web applications with security, logging, and performance features built-in.
0 commit comments