Conversation
- Make underlying HTTP server, callbacks, and server configuration optional in createWsServer and createRpcServer - Support Express applications / request listener functions directly in httpServer option - Support automatic port binding via port option and expose httpServer on WsServer and RpcServer - Make serverParams optional in apiDefinition.createServer - Fix DefinitionTypeOutput to extract Zod output structurally, eliminating 'Type instantiation is excessively deep' errors on complex schemas - Add comprehensive test suite covering all DevEx improvements and complex Zod schemas Resolves autonomys#356, autonomys#448
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 541446c. Configure here.
| httpServer.close() | ||
| httpServer.closeAllConnections?.() | ||
| } | ||
| } |
There was a problem hiding this comment.
Close leaks server during listen race
Medium Severity
close only shuts down the HTTP server when httpServer.listening is already true. listen, including the new port option, starts an asynchronous bind, so listening is still false immediately afterward. Calling close in that window leaves the socket bound after startup completes.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 541446c. Configure here.
| const listen = (port: number, cb?: () => void) => { | ||
| internalHttpServer.listen(port, cb) | ||
| if (typeof port === 'number') { | ||
| listen(port) |
There was a problem hiding this comment.
Listen mishandles overlapping bind attempts
Medium Severity
listen treats only httpServer.listening as already-started. After the port option kicks off an async bind, listening is still false, so a follow-up listen calls httpServer.listen again and throws. Once listening, a later listen with a different port still runs the success callback without rebinding.
Reviewed by Cursor Bugbot for commit 541446c. Configure here.
| } else if (typeof rawHttpServer === 'function') { | ||
| httpServer = http.createServer(wrapRequestListener(rawHttpServer)) | ||
| } else { | ||
| httpServer = http.createServer() |
There was a problem hiding this comment.
Default server hangs non-RPC requests
Low Severity
When no httpServer is provided, the default http.createServer() has no fallback handler. Only POST /ws is answered later. Other HTTP requests never receive a response and hold the connection open until timeout.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 541446c. Configure here.


Resolves #356
Resolves #448
Summary
This PR addresses developer experience and typing issues in
@autonomys/rpc:Ease Underlying HTTP Server ([@autonomys/rpc] Ease the underlying HTTP server #356):
httpServer,callbacks, and server configuration optional with sensible defaults.httpServer.portdirectly in configuration options or callingserver.listen(port).serverParamsoptional inapiDefinition.createServer.httpServer: http.Serverdirectly onWsServerandRpcServer.Zod Validator Type Resolution ([
@autonomys/rpc] Type resolution fails when usingzodvalidators #448):DefinitionTypeOutputto structurally extract output types from Zod schemas, resolving theType instantiation is excessively deep and possibly infiniteerror on complex schemas.Test Suite:
__test__/rpc/httpServerDevEx.spec.tscovering Express app integration, port binding, default instantiation, and complex nested Zod schemas.