MCPcopy Create free account
hub / github.com/fastify/fastify / prepareRoute

Function prepareRoute

lib/route.js:141–169  ·  view source on GitHub ↗
({ method, url, options, handler, isFastify })

Source from the content-addressed store, hash-verified

139
140 // Convert shorthand to extended route declaration
141 function prepareRoute ({ method, url, options, handler, isFastify }) {
142 if (typeof url !== 'string') {
143 throw new FST_ERR_INVALID_URL(typeof url)
144 }
145
146 if (!handler && typeof options === 'function') {
147 handler = options // for support over direct function calls such as fastify.get() options are reused as the handler
148 options = {}
149 } else if (handler && typeof handler === 'function') {
150 if (Object.prototype.toString.call(options) !== '[object Object]') {
151 throw new FST_ERR_ROUTE_OPTIONS_NOT_OBJ(method, url)
152 } else if (options.handler) {
153 if (typeof options.handler === 'function') {
154 throw new FST_ERR_ROUTE_DUPLICATED_HANDLER(method, url)
155 } else {
156 throw new FST_ERR_ROUTE_HANDLER_NOT_FN(method, url)
157 }
158 }
159 }
160
161 options = Object.assign({}, options, {
162 method,
163 url,
164 path: url,
165 handler: handler || (options && options.handler)
166 })
167
168 return route.call(this, { options, isFastify })
169 }
170
171 function hasRoute ({ options }) {
172 const normalizedMethod = options.method?.toUpperCase() ?? ''

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected