This is a short version of readme, for more information see the readme of the plugin system here
Locking down the microservice slows down development and usages, because adding new features to the main repository may take a lot of time. Instead, plugin system for loading modules dynamically using a single config file.
To add a plugin, add plugins.json
file in the directory, where microservice is running and add plugin definitions.
The file should consist of an array, with each entry representing one plugin.
Simples plugin definition is just the name of the NPM package
[
"@longucodes/auth-plugin-rabbitmq"
]
The plugin will be automatically installed by the cli and loaded into the application.
To add more capabilities, like config or specific version, advanced definition should be used.
[
{
"name": "@longucodes/auth-plugin-rabbitmq"
}
]
In addition to name, following properties can be provided.
version
- install specific version of the packagemode
- can bestatic
(default) anddynamic
. Dynamic plugins will not be installed by cliconfig
- object with configuration values
The config object can contain direct values or read them from environment.
To use environment variable , the config value should be the name of the environment variable with $
at the beginning.
All variables consisting only of uppercase letters and _
, and a $
will be treated as a environment variable read.
[
{
"name": "@longucodes/auth-plugin-rabbitmq",
"config": {
"url": "staticUrl",
"exchange": "$ENV_VARIABLE"
}
}
]
Not all plugins are configurable, check documentation of used plugin.
To create your own plugin, create NPM package, that default exports a Nestjs module. If you want your package to be configurable, add static method forRoot
returning a dynamic module.