Aktueller Stand
This commit is contained in:
24
backend/node_modules/fastify-plugin/README.md
generated
vendored
24
backend/node_modules/fastify-plugin/README.md
generated
vendored
@@ -1,18 +1,24 @@
|
||||
# fastify-plugin
|
||||
|
||||

|
||||
[](https://github.com/fastify/fastify-plugin/actions/workflows/ci.yml)
|
||||
[](https://www.npmjs.com/package/fastify-plugin)
|
||||
[](https://standardjs.com/)
|
||||
[](https://github.com/neostandard/neostandard)
|
||||
|
||||
`fastify-plugin` is a plugin helper for [Fastify](https://github.com/fastify/fastify).
|
||||
|
||||
When you build plugins for Fastify and you want that them to be accessible in the same context where you require them, you have two ways:
|
||||
When you build plugins for Fastify and you want them to be accessible in the same context where you require them, you have two ways:
|
||||
1. Use the `skip-override` hidden property
|
||||
2. Use this module
|
||||
|
||||
__Note: the v4.x series of this module covers Fastify v4__
|
||||
__Note: the v2.x & v3.x series of this module covers Fastify v3. For Fastify v2 support, refer to the v1.x series.__
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm i fastify-plugin
|
||||
```
|
||||
|
||||
## Usage
|
||||
`fastify-plugin` can do three things for you:
|
||||
- Add the `skip-override` hidden property
|
||||
@@ -51,7 +57,7 @@ const fp = require('fastify-plugin')
|
||||
module.exports = fp(function (fastify, opts, done) {
|
||||
// your plugin code
|
||||
done()
|
||||
}, { fastify: '4.x' })
|
||||
}, { fastify: '5.x' })
|
||||
```
|
||||
|
||||
If you need to check the Fastify version only, you can pass just the version string.
|
||||
@@ -70,7 +76,7 @@ function plugin (fastify, opts, done) {
|
||||
}
|
||||
|
||||
module.exports = fp(plugin, {
|
||||
fastify: '4.x',
|
||||
fastify: '5.x',
|
||||
name: 'your-plugin-name'
|
||||
})
|
||||
```
|
||||
@@ -87,7 +93,7 @@ function plugin (fastify, opts, done) {
|
||||
}
|
||||
|
||||
module.exports = fp(plugin, {
|
||||
fastify: '4.x',
|
||||
fastify: '5.x',
|
||||
decorators: {
|
||||
fastify: ['plugin1', 'plugin2'],
|
||||
reply: ['compress']
|
||||
@@ -111,7 +117,7 @@ function plugin (fastify, opts, done) {
|
||||
|
||||
module.exports = fp(plugin, {
|
||||
name: 'my-encapsulated-plugin',
|
||||
fastify: '4.x',
|
||||
fastify: '5.x',
|
||||
decorators: {
|
||||
fastify: ['plugin1', 'plugin2'],
|
||||
reply: ['compress']
|
||||
@@ -136,7 +142,7 @@ fp((fastify, opts, done) => { done() })
|
||||
fp(async (fastify, opts) => { return })
|
||||
```
|
||||
|
||||
TypeScript can sometimes infer the types of the arguments for these functions. Plugins in fastify are recommended to be typed using either `FastifyPluginCallback` or `FastifyPluginAsync`. These two definitions only differ in two ways:
|
||||
TypeScript can sometimes infer the types of the arguments for these functions. Plugins in Fastify are recommended to be typed using either `FastifyPluginCallback` or `FastifyPluginAsync`. These two definitions only differ in two ways:
|
||||
|
||||
1. The third argument `done` (the callback part)
|
||||
2. The return type `FastifyPluginCallback` or `FastifyPluginAsync`
|
||||
@@ -171,7 +177,7 @@ fp(pluginAsyncWithTypes)
|
||||
fp(async (fastify: FastifyInstance, options: FastifyPluginOptions): Promise<void> => { })
|
||||
```
|
||||
|
||||
## Acknowledgements
|
||||
## Acknowledgments
|
||||
|
||||
This project is kindly sponsored by:
|
||||
- [nearForm](https://nearform.com)
|
||||
|
||||
Reference in New Issue
Block a user