(options, defaultRoute, onBadUrl, onMaxParamLength)
| 850 | } |
| 851 | |
| 852 | function processOptions (options, defaultRoute, onBadUrl, onMaxParamLength) { |
| 853 | // Options validations |
| 854 | if (options && typeof options !== 'object') { |
| 855 | throw new FST_ERR_OPTIONS_NOT_OBJ() |
| 856 | } else { |
| 857 | // Shallow copy options object to prevent mutations outside of this function |
| 858 | options = Object.assign({}, options) |
| 859 | } |
| 860 | |
| 861 | if ( |
| 862 | (options.querystringParser && typeof options.querystringParser !== 'function') || |
| 863 | ( |
| 864 | options.routerOptions?.querystringParser && |
| 865 | typeof options.routerOptions.querystringParser !== 'function' |
| 866 | ) |
| 867 | ) { |
| 868 | throw new FST_ERR_QSP_NOT_FN(typeof (options.querystringParser ?? options.routerOptions.querystringParser)) |
| 869 | } |
| 870 | |
| 871 | if (options.schemaController && options.schemaController.bucket && typeof options.schemaController.bucket !== 'function') { |
| 872 | throw new FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN(typeof options.schemaController.bucket) |
| 873 | } |
| 874 | |
| 875 | validateBodyLimitOption(options.bodyLimit) |
| 876 | |
| 877 | const requestIdHeader = typeof options.requestIdHeader === 'string' && options.requestIdHeader.length !== 0 ? options.requestIdHeader.toLowerCase() : (options.requestIdHeader === true && 'request-id') |
| 878 | const genReqId = reqIdGenFactory(requestIdHeader, options.genReqId) |
| 879 | const requestIdLogLabel = options.requestIdLogLabel || 'reqId' |
| 880 | options.bodyLimit = options.bodyLimit || defaultInitOptions.bodyLimit |
| 881 | const disableRequestLogging = options.disableRequestLogging || false |
| 882 | |
| 883 | const ajvOptions = Object.assign({ |
| 884 | customOptions: {}, |
| 885 | plugins: [] |
| 886 | }, options.ajv) |
| 887 | |
| 888 | if (!ajvOptions.customOptions || Object.prototype.toString.call(ajvOptions.customOptions) !== '[object Object]') { |
| 889 | throw new FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ(typeof ajvOptions.customOptions) |
| 890 | } |
| 891 | if (!ajvOptions.plugins || !Array.isArray(ajvOptions.plugins)) { |
| 892 | throw new FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR(typeof ajvOptions.plugins) |
| 893 | } |
| 894 | |
| 895 | const { logger, hasLogger } = createLogger(options) |
| 896 | |
| 897 | // Update the options with the fixed values |
| 898 | options.connectionTimeout = options.connectionTimeout || defaultInitOptions.connectionTimeout |
| 899 | options.keepAliveTimeout = options.keepAliveTimeout || defaultInitOptions.keepAliveTimeout |
| 900 | options.maxRequestsPerSocket = options.maxRequestsPerSocket || defaultInitOptions.maxRequestsPerSocket |
| 901 | options.requestTimeout = options.requestTimeout || defaultInitOptions.requestTimeout |
| 902 | options.logger = logger |
| 903 | options.requestIdHeader = requestIdHeader |
| 904 | options.requestIdLogLabel = requestIdLogLabel |
| 905 | options.disableRequestLogging = disableRequestLogging |
| 906 | options.ajv = ajvOptions |
| 907 | options.clientErrorHandler = options.clientErrorHandler || defaultClientErrorHandler |
| 908 | options.allowErrorHandlerOverride = options.allowErrorHandlerOverride ?? defaultInitOptions.allowErrorHandlerOverride |
| 909 |
no test coverage detected
searching dependent graphs…