({ path, prefixing = false, isFastify = false })
| 279 | return this |
| 280 | |
| 281 | function addNewRoute ({ path, prefixing = false, isFastify = false }) { |
| 282 | const url = prefix + path |
| 283 | |
| 284 | opts.url = url |
| 285 | opts.path = url |
| 286 | opts.routePath = path |
| 287 | opts.prefix = prefix |
| 288 | opts.logLevel = opts.logLevel || this[kLogLevel] |
| 289 | validateLogLevelOption(opts.logLevel, opts.method, opts.url, logger) |
| 290 | |
| 291 | if (this[kLogSerializers] || opts.logSerializers) { |
| 292 | opts.logSerializers = Object.assign(Object.create(this[kLogSerializers]), opts.logSerializers) |
| 293 | } |
| 294 | |
| 295 | if (opts.attachValidation == null) { |
| 296 | opts.attachValidation = false |
| 297 | } |
| 298 | |
| 299 | if (prefixing === false) { |
| 300 | // run 'onRoute' hooks |
| 301 | for (const hook of this[kHooks].onRoute) { |
| 302 | hook.call(this, opts) |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | for (const hook of lifecycleHooks) { |
| 307 | if (opts && hook in opts) { |
| 308 | if (Array.isArray(opts[hook])) { |
| 309 | for (const func of opts[hook]) { |
| 310 | if (typeof func !== 'function') { |
| 311 | throw new FST_ERR_HOOK_INVALID_HANDLER(hook, Object.prototype.toString.call(func)) |
| 312 | } |
| 313 | |
| 314 | if (hook === 'onSend' || hook === 'preSerialization' || hook === 'onError' || hook === 'preParsing') { |
| 315 | if (func.constructor.name === 'AsyncFunction' && func.length === 4) { |
| 316 | throw new FST_ERR_HOOK_INVALID_ASYNC_HANDLER() |
| 317 | } |
| 318 | } else if (hook === 'onRequestAbort') { |
| 319 | if (func.constructor.name === 'AsyncFunction' && func.length !== 1) { |
| 320 | throw new FST_ERR_HOOK_INVALID_ASYNC_HANDLER() |
| 321 | } |
| 322 | } else { |
| 323 | if (func.constructor.name === 'AsyncFunction' && func.length === 3) { |
| 324 | throw new FST_ERR_HOOK_INVALID_ASYNC_HANDLER() |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | } else if (opts[hook] !== undefined && typeof opts[hook] !== 'function') { |
| 329 | throw new FST_ERR_HOOK_INVALID_HANDLER(hook, Object.prototype.toString.call(opts[hook])) |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | const constraints = opts.constraints || {} |
| 335 | const config = { |
| 336 | ...opts.config, |
| 337 | url, |
| 338 | method: opts.method |
nothing calls this directly
no test coverage detected