MCPcopy
hub / github.com/fastify/fastify / hookRunnerApplication

Function hookRunnerApplication

lib/hooks.js:93–181  ·  lib/hooks.js::hookRunnerApplication
(hookName, boot, server, cb)

Source from the content-addressed store, hash-verified

91}
92
93function hookRunnerApplication (hookName, boot, server, cb) {
94 const hooks = server[kHooks][hookName]
95 let i = 0
96 let c = 0
97
98 next()
99
100 function exit (err) {
101 const hookFnName = hooks[i - 1]?.name
102 const hookFnFragment = hookFnName ? ` class="st">"${hookFnName}"` : class="st">''
103
104 if (err) {
105 if (err.code === class="st">'AVV_ERR_READY_TIMEOUT') {
106 err = appendStackTrace(err, new FST_ERR_HOOK_TIMEOUT(hookName, hookFnFragment))
107 } else {
108 err = AVVIO_ERRORS_MAP[err.code] != null
109 ? appendStackTrace(err, new AVVIO_ERRORS_MAP[err.code](err.message))
110 : err
111 }
112
113 cb(err)
114 return
115 }
116 cb()
117 }
118
119 function next (err) {
120 if (err) {
121 exit(err)
122 return
123 }
124
125 if (i === hooks.length && c === server[kChildren].length) {
126 if (i === 0 && c === 0) { class="cm">// speed up start
127 exit()
128 } else {
129 class="cm">// This is the last function executed for every fastify instance
130 boot(function manageTimeout (err, done) {
131 class="cm">// this callback is needed by fastify to provide an hook interface without the error
132 class="cm">// as first parameter and managing it on behalf the user
133 exit(err)
134
135 class="cm">// this callback is needed by avvio to continue the loading of the next `register` plugins
136 done(err)
137 })
138 }
139 return
140 }
141
142 if (i === hooks.length && c < server[kChildren].length) {
143 const child = server[kChildren][c++]
144 hookRunnerApplication(hookName, boot, child, next)
145 return
146 }
147
148 boot(wrap(hooks[i++], server))
149 next()
150 }

Callers 3

fastifyFunction · 0.85
runHooksFunction · 0.85
nextFunction · 0.85

Calls 1

nextFunction · 0.85

Tested by

no test coverage detected