diff --git a/index.js b/index.js index ec3b07d..6315586 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,9 @@ function replyAcceptMethod () { function fastifyAccepts (fastify, options, done) { fastify.decorateRequest('accepts', acceptsMethod) - methodNames.forEach(methodName => { + const methodNamesLength = methodNames.length + for (let i = 0; i < methodNamesLength; i += 1) { + const methodName = methodNames[i] // Defining methods this way to ensure named functions show in stack traces fastify.decorateRequest(methodName, { [methodName]: function (arr) { @@ -42,12 +44,13 @@ function fastifyAccepts (fastify, options, done) { return acceptsObject[methodName](arr) } }[methodName]) - }) + } if (options.decorateReply === true) { fastify.decorateReply('requestAccepts', replyAcceptMethod) - methodNames.forEach(methodName => { + for (let i = 0; i < methodNamesLength; i += 1) { + const methodName = methodNames[i] const capitalizedMethodName = methodName.replace(/(?:^|\s)\S/gu, a => a.toUpperCase()) const replyMethodName = 'request' + capitalizedMethodName const acceptsMethodName = 'accepts' + capitalizedMethodName @@ -59,7 +62,7 @@ function fastifyAccepts (fastify, options, done) { return acceptsObject[methodName](arr) } }[acceptsMethodName]) - }) + } } done()