Home / Function/ module() — fastify Function Reference

module() — fastify Function Reference

Architecture documentation for the module() function in plugin-override.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  8f032db4_406b_2857_6dbc_0f64d681afb5["module()"]
  be24bd7b_f1cd_889a_75cb_83e4cace8260["plugin-override.js"]
  8f032db4_406b_2857_6dbc_0f64d681afb5 -->|defined in| be24bd7b_f1cd_889a_75cb_83e4cace8260
  f25fe79a_ed94_8b5c_60ec_32b8b7b414e0["buildRoutePrefix()"]
  8f032db4_406b_2857_6dbc_0f64d681afb5 -->|calls| f25fe79a_ed94_8b5c_60ec_32b8b7b414e0
  style 8f032db4_406b_2857_6dbc_0f64d681afb5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/plugin-override.js lines 28–74

module.exports = function override (old, fn, opts) {
  const shouldSkipOverride = pluginUtils.registerPlugin.call(old, fn)

  const fnName = pluginUtils.getPluginName(fn) || pluginUtils.getFuncPreview(fn)
  if (shouldSkipOverride) {
    // after every plugin registration we will enter a new name
    old[kPluginNameChain].push(fnName)
    return old
  }

  const instance = Object.create(old)
  old[kChildren].push(instance)
  instance.ready = old[kAvvioBoot].bind(instance)
  instance[kChildren] = []

  instance[kReply] = Reply.buildReply(instance[kReply])
  instance[kRequest] = Request.buildRequest(instance[kRequest])

  instance[kContentTypeParser] = ContentTypeParser.helpers.buildContentTypeParser(instance[kContentTypeParser])
  instance[kHooks] = buildHooks(instance[kHooks])
  instance[kRoutePrefix] = buildRoutePrefix(instance[kRoutePrefix], opts.prefix)
  instance[kLogLevel] = opts.logLevel || instance[kLogLevel]
  instance[kSchemaController] = SchemaController.buildSchemaController(old[kSchemaController])
  instance.getSchema = instance[kSchemaController].getSchema.bind(instance[kSchemaController])
  instance.getSchemas = instance[kSchemaController].getSchemas.bind(instance[kSchemaController])

  // Track the registered and loaded plugins since the root instance.
  // It does not track the current encapsulated plugin.
  instance[pluginUtils.kRegisteredPlugins] = Object.create(instance[pluginUtils.kRegisteredPlugins])

  // Track the plugin chain since the root instance.
  // When an non-encapsulated plugin is added, the chain will be updated.
  instance[kPluginNameChain] = [fnName]
  instance[kErrorHandlerAlreadySet] = false

  if (instance[kLogSerializers] || opts.logSerializers) {
    instance[kLogSerializers] = Object.assign(Object.create(instance[kLogSerializers]), opts.logSerializers)
  }

  if (opts.prefix) {
    instance[kFourOhFour].arrange404(instance)
  }

  for (const hook of instance[kHooks].onRegister) hook.call(old, instance, opts)

  return instance
}

Domain

Subdomains

Frequently Asked Questions

What does module() do?
module() is a function in the fastify codebase, defined in lib/plugin-override.js.
Where is module() defined?
module() is defined in lib/plugin-override.js at line 28.
What does module() call?
module() calls 1 function(s): buildRoutePrefix.

Analyze Your Own Codebase

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

Try Supermodel Free