Skip to content

Instantly share code, notes, and snippets.

@RafaelGSS
Last active July 26, 2019 01:12
Show Gist options
  • Save RafaelGSS/55653247c21ec4397cf4abd9438baecd to your computer and use it in GitHub Desktop.
Save RafaelGSS/55653247c21ec4397cf4abd9438baecd to your computer and use it in GitHub Desktop.
Example Fastify Plugin
module.exports = (fastify, opts, next) => {
console.log(fastify.configuration) // { db: 'alguma-database', port: 800 }
fastify.decorate('configurationPlugin1', {
name: 'plugin1'
})
console.log(fastify.configurationPlugin1) // { name: 'plugin1' }
next() // Nunca se esqueça de liberar esse handler com `next`.
}
// Caso você queira utilizar o async/await você também pode! E não precisa chamar `next`!
// module.exposts = async function (fastify, opt) {
// console.log(fastify.configuration)
// fastify.decorate('configurationPlugin1', {
// name: 'plugin1'
// })
// console.log(this.configurationPlugin1) // { name: 'plugin' }
// }
module.exports = (fastify, opts, next) => {
console.log(fastify.configuration) // { db: 'alguma-database', port: 800 }
console.log(fastify.configurationPlugin1) // undefined
next() // Nunca se esqueça de liberar esse handler com `next`.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment