graceful
graceful(
handler,options?):Promise<{server:Server<typeofIncomingMessage, typeofServerResponse>;shutdown: (signal) =>Promise<void>; }>
Defined in: lifecycle.js:48
Creates and manages a graceful HTTP server lifecycle.
Parameters
Section titled “Parameters”handler
Section titled “handler”Function
HTTP request handler (req, res) => void
options?
Section titled “options?”Lifecycle configuration
(code?) => void
Exit function (override for testing)
hostname?
Section titled “hostname?”string
Hostname to bind to
{ error: (…args) => void; info: (…args) => void; warn: (…args) => void; }
Logger with .info(), .warn(), .error() methods
log.error
Section titled “log.error”(…args) => void
log.info
Section titled “log.info”(…args) => void
log.warn
Section titled “log.warn”(…args) => void
onShutdown?
Section titled “onShutdown?”(ctx) => void | Promise<void>
Hook called after server.close().
Receives {log, signal}. Errors are caught and logged; shutdown continues.
onStartup?
Section titled “onStartup?”(ctx) => void | Promise<void>
Hook called before server.listen().
Receives {log}. Rejection prevents the server from starting.
number
Port to listen on
signals?
Section titled “signals?”string[]
OS signals that trigger shutdown
timeout?
Section titled “timeout?”number
Maximum time (ms) to wait for connections to drain
Returns
Section titled “Returns”Promise<{ server: Server<typeof IncomingMessage, typeof ServerResponse>; shutdown: (signal) => Promise<void>; }>