@shetty4l/core 0.1.32 → 0.1.33

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 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shetty4l/core",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "description": "Shared infrastructure primitives for Bun/TypeScript services",
5
5
  "repository": {
6
6
  "type": "git",
package/src/http.ts CHANGED
@@ -92,6 +92,11 @@ export interface ServerOpts {
92
92
  version: string,
93
93
  startTime: number,
94
94
  ) => Response | Promise<Response>;
95
+ /**
96
+ * Maximum seconds a connection may be idle before the server closes it.
97
+ * Passed directly to Bun.serve(). Defaults to Bun's built-in default (10s).
98
+ */
99
+ idleTimeout?: number;
95
100
  }
96
101
 
97
102
  export interface HttpServer {
@@ -111,13 +116,22 @@ export interface HttpServer {
111
116
  * 4. If onRequest returns null -> 404
112
117
  */
113
118
  export function createServer(opts: ServerOpts): HttpServer {
114
- const { port, host = "127.0.0.1", version, onRequest, onHealth, name } = opts;
119
+ const {
120
+ port,
121
+ host = "127.0.0.1",
122
+ version,
123
+ onRequest,
124
+ onHealth,
125
+ name,
126
+ idleTimeout,
127
+ } = opts;
115
128
  const startTime = Date.now();
116
129
  const prefix = name ? `${name}: ` : "";
117
130
 
118
131
  const server = Bun.serve({
119
132
  port,
120
133
  hostname: host,
134
+ ...(idleTimeout != null && { idleTimeout }),
121
135
  async fetch(req: Request): Promise<Response> {
122
136
  const url = new URL(req.url);
123
137