MCPcopy
hub / github.com/fastify/fastify / getServerInstance

Function getServerInstance

lib/server.js:309–348  ·  lib/server.js::getServerInstance
(options, httpHandler)

Source from the content-addressed store, hash-verified

307}
308
309function getServerInstance (options, httpHandler) {
310 if (options.serverFactory) {
311 class="cm">// User provided server instance
312 return options.serverFactory(httpHandler, options)
313 }
314
315 class="cm">// We have accepted true as a valid way to init https but node requires an options obj
316 const httpsOptions = options.https === true ? {} : options.https
317
318 if (options.http2) {
319 const server = typeof httpsOptions === class="st">'object' ? http2.createSecureServer(httpsOptions, httpHandler) : http2.createServer(options.http, httpHandler)
320 server.on(class="st">'session', (session) => session.setTimeout(options.http2SessionTimeout, () => {
321 session.close()
322 }))
323
324 class="cm">// This is only needed for Node.js versions < 24.0.0 since Node.js added native
325 class="cm">// closeAllSessions() on server.close() support for HTTP/2 servers in v24.0.0
326 if (options.forceCloseConnections === true) {
327 server.closeHttp2Sessions = createCloseHttp2SessionsByHttp2Server(server)
328 }
329
330 server.setTimeout(options.connectionTimeout)
331
332 return server
333 }
334
335 class="cm">// HTTP1 server instance
336 const server = httpsOptions
337 ? https.createServer(httpsOptions, httpHandler)
338 : http.createServer(options.http, httpHandler)
339 server.keepAliveTimeout = options.keepAliveTimeout
340 server.requestTimeout = options.requestTimeout
341 server.setTimeout(options.connectionTimeout)
342 class="cm">// We treat zero as null(node default) so we do not pass zero to the server instance
343 if (options.maxRequestsPerSocket > 0) {
344 server.maxRequestsPerSocket = options.maxRequestsPerSocket
345 }
346
347 return server
348}
349
350/**
351 * Inspects the provided `server.address` object and returns a

Callers 2

createServerFunction · 0.85
multipleBindingsFunction · 0.85

Calls 2

closeMethod · 0.80

Tested by

no test coverage detected