Home / Function/ buildRouting() — fastify Function Reference

buildRouting() — fastify Function Reference

Architecture documentation for the buildRouting() function in route.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  6cd5988e_5d78_05dc_2f41_2265e76dcba8["buildRouting()"]
  de54192b_022b_f89b_5a43_a2593cb4df49["route.js"]
  6cd5988e_5d78_05dc_2f41_2265e76dcba8 -->|defined in| de54192b_022b_f89b_5a43_a2593cb4df49
  9f6489a1_be37_aace_6969_5f938cfb179f["validateBodyLimitOption()"]
  6cd5988e_5d78_05dc_2f41_2265e76dcba8 -->|calls| 9f6489a1_be37_aace_6969_5f938cfb179f
  3ffd7b0c_8a51_29ad_9075_fc261f654dec["runPreParsing()"]
  6cd5988e_5d78_05dc_2f41_2265e76dcba8 -->|calls| 3ffd7b0c_8a51_29ad_9075_fc261f654dec
  style 6cd5988e_5d78_05dc_2f41_2265e76dcba8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/route.js lines 70–555

function buildRouting (options) {
  const router = FindMyWay(options)

  let avvio
  let fourOhFour
  let logger
  let hasLogger
  let setupResponseListeners
  let throwIfAlreadyStarted
  let disableRequestLogging
  let disableRequestLoggingFn
  let ignoreTrailingSlash
  let ignoreDuplicateSlashes
  let return503OnClosing
  let globalExposeHeadRoutes
  let keepAliveConnections

  let closing = false

  return {
    /**
     * @param {import('../fastify').FastifyServerOptions} options
     * @param {*} fastifyArgs
     */
    setup (options, fastifyArgs) {
      avvio = fastifyArgs.avvio
      fourOhFour = fastifyArgs.fourOhFour
      logger = options.logger
      hasLogger = fastifyArgs.hasLogger
      setupResponseListeners = fastifyArgs.setupResponseListeners
      throwIfAlreadyStarted = fastifyArgs.throwIfAlreadyStarted

      globalExposeHeadRoutes = options.exposeHeadRoutes
      disableRequestLogging = options.disableRequestLogging
      if (typeof disableRequestLogging === 'function') {
        disableRequestLoggingFn = options.disableRequestLogging
      }

      ignoreTrailingSlash = options.routerOptions.ignoreTrailingSlash
      ignoreDuplicateSlashes = options.routerOptions.ignoreDuplicateSlashes
      return503OnClosing = Object.hasOwn(options, 'return503OnClosing') ? options.return503OnClosing : true
      keepAliveConnections = fastifyArgs.keepAliveConnections
    },
    routing: router.lookup.bind(router), // router func to find the right handler to call
    route, // configure a route in the fastify instance
    hasRoute,
    prepareRoute,
    routeHandler,
    closeRoutes: () => { closing = true },
    printRoutes: router.prettyPrint.bind(router),
    addConstraintStrategy,
    hasConstraintStrategy,
    isAsyncConstraint,
    findRoute
  }

  function addConstraintStrategy (strategy) {
    throwIfAlreadyStarted('Cannot add constraint strategy!')
    return router.addConstraintStrategy(strategy)
  }

  function hasConstraintStrategy (strategyName) {
    return router.hasConstraintStrategy(strategyName)
  }

  function isAsyncConstraint () {
    return router.constrainer.asyncStrategiesInUse.size > 0
  }

  // Convert shorthand to extended route declaration
  function prepareRoute ({ method, url, options, handler, isFastify }) {
    if (typeof url !== 'string') {
      throw new FST_ERR_INVALID_URL(typeof url)
    }

    if (!handler && typeof options === 'function') {
      handler = options // for support over direct function calls such as fastify.get() options are reused as the handler
      options = {}
    } else if (handler && typeof handler === 'function') {
      if (Object.prototype.toString.call(options) !== '[object Object]') {
        throw new FST_ERR_ROUTE_OPTIONS_NOT_OBJ(method, url)

Domain

Subdomains

Defined In

Frequently Asked Questions

What does buildRouting() do?
buildRouting() is a function in the fastify codebase, defined in lib/route.js.
Where is buildRouting() defined?
buildRouting() is defined in lib/route.js at line 70.
What does buildRouting() call?
buildRouting() calls 2 function(s): runPreParsing, validateBodyLimitOption.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free