Last active
July 26, 2019 01:12
-
-
Save RafaelGSS/55653247c21ec4397cf4abd9438baecd to your computer and use it in GitHub Desktop.
Example Fastify Plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } | |
// } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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