@shetty4l/core 0.1.28 → 0.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/http.ts +15 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shetty4l/core",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "description": "Shared infrastructure primitives for Bun/TypeScript services",
5
5
  "repository": {
6
6
  "type": "git",
package/src/http.ts CHANGED
@@ -81,6 +81,17 @@ export interface ServerOpts {
81
81
  req: Request,
82
82
  url: URL,
83
83
  ) => Response | Promise<Response> | null | Promise<Response | null>;
84
+ /**
85
+ * Optional custom health endpoint handler.
86
+ * When provided, called instead of the default healthResponse().
87
+ * Return a full Response to control both body and HTTP status
88
+ * (e.g. 503 for degraded state). Use healthResponse() inside
89
+ * the handler for the standard healthy case.
90
+ */
91
+ onHealth?: (
92
+ version: string,
93
+ startTime: number,
94
+ ) => Response | Promise<Response>;
84
95
  }
85
96
 
86
97
  export interface HttpServer {
@@ -100,7 +111,7 @@ export interface HttpServer {
100
111
  * 4. If onRequest returns null -> 404
101
112
  */
102
113
  export function createServer(opts: ServerOpts): HttpServer {
103
- const { port, host = "127.0.0.1", version, onRequest, name } = opts;
114
+ const { port, host = "127.0.0.1", version, onRequest, onHealth, name } = opts;
104
115
  const startTime = Date.now();
105
116
  const prefix = name ? `${name}: ` : "";
106
117
 
@@ -115,7 +126,9 @@ export function createServer(opts: ServerOpts): HttpServer {
115
126
  }
116
127
 
117
128
  if (url.pathname === "/health" && req.method === "GET") {
118
- return healthResponse(version, startTime);
129
+ return onHealth
130
+ ? onHealth(version, startTime)
131
+ : healthResponse(version, startTime);
119
132
  }
120
133
 
121
134
  try {