Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/devframe/src/node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ export interface StartHttpAndWsOptions {
* own startup banner. Devframe does not print one itself.
*/
onReady?: (info: { origin: string, port: number, app: H3 }) => void | Promise<void>
/**
* Called for any error the HTTP server devframe owns emits after it starts
* listening — e.g. a transient `EMFILE` while accepting a connection.
* Without it such an error has no listener and crashes the process.
*
* Applies only to a server devframe created itself. When `server` is
* supplied the caller owns that object and attaches to it directly, so
* devframe leaves its error handling alone.
*/
onServerError?: (error: Error) => void
}

export interface StartedServer {
Expand Down Expand Up @@ -279,6 +289,10 @@ export async function startHttpAndWs(options: StartHttpAndWsOptions): Promise<St
cause: error,
})
}
// Attached only now that the bind has already succeeded — this never
// changes bind-time crash/hang semantics, only what happens afterward.
if (options.onServerError)
httpServer.on('error', options.onServerError)
}

const address = httpServer.address()
Expand Down
Loading