Comments (5)
Can you please make an example of what you think it's happening right now vs what it should be happening according to you?
from fastify-plugin.
@mcollina I like how it works now, but I would improve the README:
I think it should be something like this
You can also pass some metadata that will be handled by Fastify, such as the dependencies of your plugin.const fp = require('fastify-plugin')
function plugin (fastify, opts, next) {
// your plugin code
next()
}
module.exports = fp(plugin, {
fastify: '0.x',
// You need to define only one of the [dependency|decorator] properties.
decorators: {
fastify: ['plugin1', 'plugin2'],
reply: ['compress']
},
dependencies: ['plugin1-name, plugin2-name']
})
And I think we should update Ecosystem plugins with name property, because
dependency
only works if the name property defined int the plugin's meta.
For example:
plugin.js
const fp = require('fastify-plugin')
function plugin (fastify, opts, next) {
// your plugin code
next()
}
module.exports = fp(plugin, {
fastify: '0.x',
dependencies: ['fastify-redis']
})
server.js
const Fastify = require('fastify')
const redis = require('fastify-redis')
const plugin = require('./plugin')
module.exports = (options) => {
const instance = Fastify()
instance
.register(redis)
.register(plugin)
// more code
return instance
}
This will throw error (even if the dependency registered), simply because fastify-redis does not have name property in its plugin definition.
from fastify-plugin.
@lependu why You need to define only one of the [dependency|decorator] properties.
?
You may need both.
from fastify-plugin.
@delvedor Corrected.
One more question: May I create PRs which updates Ecosystem plugins with name
property?
from fastify-plugin.
Sure!
from fastify-plugin.
Related Issues (20)
- `fastify not found, proceeding anyway` if running ES module Node.js program HOT 4
- Typescript error on usage HOT 1
- Add example using async/await
- Coverage 100% HOT 1
- Make plugin name more accessible HOT 4
- Rename package? @fastify/plugin HOT 1
- TS: Left side of comma operator is unused and has no side effects. HOT 5
- missing v4 release? HOT 4
- named exports are not right after renaming the modules
- Cannot pass in RawServer generic type HOT 8
- Introduce an option to encapsulate the plugin HOT 2
- Rename this module HOT 34
- Broken Typescript types when defining options and done HOT 23
- Validate if a rewrite in TS has any performance penalty HOT 19
- fn invalid parameters after 4.5.1 update HOT 5
- Update the documentation to reflect typescript changes from v 4.5.1 HOT 1
- extractPluginName sometimes fails with Bun HOT 1
- Issue v5 release
- custom error handler not breaking encapsulation using fastify-plugin HOT 2
- fastify-plugin cannot be bundle
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-plugin.