* @param {import('./fastify.js').FastifyServerOptions} serverOptions
(serverOptions)
| 88 | * @param {import('./fastify.js').FastifyServerOptions} serverOptions |
| 89 | */ |
| 90 | function fastify (serverOptions) { |
| 91 | const { |
| 92 | options, |
| 93 | genReqId, |
| 94 | logController, |
| 95 | hasLogger, |
| 96 | initialConfig |
| 97 | } = processOptions(serverOptions, defaultRoute, onBadUrl, onMaxParamLength) |
| 98 | |
| 99 | // Default router |
| 100 | const router = buildRouting(options.routerOptions) |
| 101 | |
| 102 | // 404 router, used for handling encapsulated 404 handlers |
| 103 | const fourOhFour = build404(options) |
| 104 | |
| 105 | // HTTP server and its handler |
| 106 | const httpHandler = wrapRouting(router, options) |
| 107 | |
| 108 | const { |
| 109 | server, |
| 110 | listen, |
| 111 | forceCloseConnections, |
| 112 | serverHasCloseAllConnections, |
| 113 | serverHasCloseHttp2Sessions, |
| 114 | keepAliveConnections |
| 115 | } = createServer(options, httpHandler) |
| 116 | |
| 117 | const setupResponseListeners = Reply.setupResponseListeners |
| 118 | const schemaController = SchemaController.buildSchemaController(null, options.schemaController) |
| 119 | |
| 120 | // Public API |
| 121 | const fastify = { |
| 122 | // Fastify internals |
| 123 | [kState]: { |
| 124 | listening: false, |
| 125 | closing: false, |
| 126 | started: false, |
| 127 | ready: false, |
| 128 | booting: false, |
| 129 | aborted: false, |
| 130 | readyResolver: null |
| 131 | }, |
| 132 | [kKeepAliveConnections]: keepAliveConnections, |
| 133 | [kSupportedHTTPMethods]: { |
| 134 | bodyless: new Set([ |
| 135 | // Standard |
| 136 | 'GET', |
| 137 | 'HEAD', |
| 138 | 'TRACE' |
| 139 | ]), |
| 140 | bodywith: new Set([ |
| 141 | // Standard |
| 142 | 'DELETE', |
| 143 | 'OPTIONS', |
| 144 | 'PATCH', |
| 145 | 'PUT', |
| 146 | 'POST' |
| 147 | ]) |
no test coverage detected