MCPcopy Create free account
hub / github.com/fastify/fastify / processOptions

Function processOptions

fastify.js:845–936  ·  view source on GitHub ↗
(options, defaultRoute, onBadUrl, onMaxParamLength)

Source from the content-addressed store, hash-verified

843}
844
845function processOptions (options, defaultRoute, onBadUrl, onMaxParamLength) {
846 // Options validations
847 if (options && typeof options !== 'object') {
848 throw new FST_ERR_OPTIONS_NOT_OBJ()
849 } else {
850 // Shallow copy options object to prevent mutations outside of this function
851 options = Object.assign({}, options)
852 }
853
854 if (
855 (options.querystringParser && typeof options.querystringParser !== 'function') ||
856 (
857 options.routerOptions?.querystringParser &&
858 typeof options.routerOptions.querystringParser !== 'function'
859 )
860 ) {
861 throw new FST_ERR_QSP_NOT_FN(typeof (options.querystringParser ?? options.routerOptions.querystringParser))
862 }
863
864 if (options.schemaController && options.schemaController.bucket && typeof options.schemaController.bucket !== 'function') {
865 throw new FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN(typeof options.schemaController.bucket)
866 }
867
868 validateBodyLimitOption(options.bodyLimit)
869
870 const requestIdHeader = typeof options.requestIdHeader === 'string' && options.requestIdHeader.length !== 0 ? options.requestIdHeader.toLowerCase() : (options.requestIdHeader === true && 'request-id')
871 const genReqId = reqIdGenFactory(requestIdHeader, options.genReqId)
872 if (options.requestIdLogLabel !== undefined) {
873 FSTDEP024()
874 }
875 options.bodyLimit = options.bodyLimit || defaultInitOptions.bodyLimit
876 if (options.disableRequestLogging !== undefined) {
877 FSTDEP023()
878 }
879
880 const ajvOptions = Object.assign({
881 customOptions: {},
882 plugins: []
883 }, options.ajv)
884
885 if (!ajvOptions.customOptions || Object.prototype.toString.call(ajvOptions.customOptions) !== '[object Object]') {
886 throw new FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ(typeof ajvOptions.customOptions)
887 }
888 if (!ajvOptions.plugins || !Array.isArray(ajvOptions.plugins)) {
889 throw new FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR(typeof ajvOptions.plugins)
890 }
891
892 const { logger, hasLogger } = createLogger(options)
893
894 // the internal logger uses the input logger to execute the logging. This allows the user
895 // to customize every internal log line
896 const logController = createLogController(options)
897
898 // Update the options with the fixed values
899 options.connectionTimeout = options.connectionTimeout || defaultInitOptions.connectionTimeout
900 options.keepAliveTimeout = options.keepAliveTimeout || defaultInitOptions.keepAliveTimeout
901 options.maxRequestsPerSocket = options.maxRequestsPerSocket || defaultInitOptions.maxRequestsPerSocket
902 options.requestTimeout = options.requestTimeout || defaultInitOptions.requestTimeout

Callers 1

fastifyFunction · 0.85

Calls 5

validateBodyLimitOptionFunction · 0.85
reqIdGenFactoryFunction · 0.85
createLoggerFunction · 0.85
createLogControllerFunction · 0.85
buildRouterOptionsFunction · 0.85

Tested by

no test coverage detected