Home / Function/ getServerInstance() — fastify Function Reference

getServerInstance() — fastify Function Reference

Architecture documentation for the getServerInstance() function in server.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  f8a56543_30d0_fd17_5f30_f1ddc20ab439["getServerInstance()"]
  39d7da74_a631_4522_4e09_0cc36c64a8f8["server.js"]
  f8a56543_30d0_fd17_5f30_f1ddc20ab439 -->|defined in| 39d7da74_a631_4522_4e09_0cc36c64a8f8
  55bc576c_6c04_1347_602f_f32a2197069f["createServer()"]
  55bc576c_6c04_1347_602f_f32a2197069f -->|calls| f8a56543_30d0_fd17_5f30_f1ddc20ab439
  183b2e81_49c4_37fc_93d0_da7f1b0f16f1["multipleBindings()"]
  183b2e81_49c4_37fc_93d0_da7f1b0f16f1 -->|calls| f8a56543_30d0_fd17_5f30_f1ddc20ab439
  55bc576c_6c04_1347_602f_f32a2197069f["createServer()"]
  f8a56543_30d0_fd17_5f30_f1ddc20ab439 -->|calls| 55bc576c_6c04_1347_602f_f32a2197069f
  998205a3_0747_9f3f_8d12_9cbdc444a8ac["createCloseHttp2SessionsByHttp2Server()"]
  f8a56543_30d0_fd17_5f30_f1ddc20ab439 -->|calls| 998205a3_0747_9f3f_8d12_9cbdc444a8ac
  style f8a56543_30d0_fd17_5f30_f1ddc20ab439 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/server.js lines 309–348

function getServerInstance (options, httpHandler) {
  if (options.serverFactory) {
    // User provided server instance
    return options.serverFactory(httpHandler, options)
  }

  // We have accepted true as a valid way to init https but node requires an options obj
  const httpsOptions = options.https === true ? {} : options.https

  if (options.http2) {
    const server = typeof httpsOptions === 'object' ? http2.createSecureServer(httpsOptions, httpHandler) : http2.createServer(options.http, httpHandler)
    server.on('session', (session) => session.setTimeout(options.http2SessionTimeout, () => {
      session.close()
    }))

    // This is only needed for Node.js versions < 24.0.0 since Node.js added native
    // closeAllSessions() on server.close() support for HTTP/2 servers in v24.0.0
    if (options.forceCloseConnections === true) {
      server.closeHttp2Sessions = createCloseHttp2SessionsByHttp2Server(server)
    }

    server.setTimeout(options.connectionTimeout)

    return server
  }

  // HTTP1 server instance
  const server = httpsOptions
    ? https.createServer(httpsOptions, httpHandler)
    : http.createServer(options.http, httpHandler)
  server.keepAliveTimeout = options.keepAliveTimeout
  server.requestTimeout = options.requestTimeout
  server.setTimeout(options.connectionTimeout)
  // We treat zero as null(node default) so we do not pass zero to the server instance
  if (options.maxRequestsPerSocket > 0) {
    server.maxRequestsPerSocket = options.maxRequestsPerSocket
  }

  return server
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does getServerInstance() do?
getServerInstance() is a function in the fastify codebase, defined in lib/server.js.
Where is getServerInstance() defined?
getServerInstance() is defined in lib/server.js at line 309.
What does getServerInstance() call?
getServerInstance() calls 2 function(s): createCloseHttp2SessionsByHttp2Server, createServer.
What calls getServerInstance()?
getServerInstance() is called by 2 function(s): createServer, multipleBindings.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free