Skip to content

Commit cb9dead

Browse files
fix: configure idleTimeout and maxRequestBodySize on the Bun server
1 parent 8e3eb79 commit cb9dead

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ io.on("connection", (socket) => {
4848

4949
export default {
5050
port: 3000,
51-
idleTimeout: 30, // must be greater than the "pingInterval" option of the engine, which defaults to 25 seconds
52-
5351
...engine.handler(),
5452
};
5553
```

lib/server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ export class Server extends EventEmitter<
413413
* });
414414
*/
415415
public handler() {
416+
const idleTimeoutInSeconds = Math.ceil(2 * this.opts.pingInterval / 1000);
417+
416418
return {
417419
fetch: (req: Request, server: Bun.Server) => {
418420
const url = new URL(req.url);
@@ -434,7 +436,11 @@ export class Server extends EventEmitter<
434436
close: (ws: BunWebSocket, code: number, message: string) => {
435437
this.onWebSocketClose(ws, code, message);
436438
},
439+
maxPayloadLength: this.opts.maxHttpBufferSize,
437440
},
441+
442+
idleTimeout: idleTimeoutInSeconds,
443+
maxRequestBodySize: this.opts.maxHttpBufferSize,
438444
};
439445
}
440446
}

0 commit comments

Comments
 (0)