Settings
Add-on can specify which settings it needs to perform its job.
Add-ons are supposed to be multi tenant capable so these settings with the tenant identifier help you to identify the correct configuration for your tenant.
How to define the settings?#
In order to specify the possible settings of the add-on, you should declare the settings
block in your addon.json
.
You can define the following types for your settings:
string
: contains the textual settingint
: contains the number setting
For example, let's create some settings for our add-on:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
In order to receive the changes in docupike, you should register the add-on again. docupike finds these changes and applies them to the add-on.
1 |
|
Updating to the same version
Usually, you have to increase the version of your add-on to show that it contains changes. You can enforce the registration process for your add-on with the same version by passing `--force` flag to the register command.Beware, not to store sensible data in the settings. User can change the settings in docupike. If you need to store credentials or other information for the business logic for the tenant, prefer to store it in your application by tenant id.
Receive the settings in your add-on#
After we registered the settings, we will receive these values with all requests from the user.
The header DATA
contains the parameters for the given user and tenant in JSON encoded format.
Let's extract the settings from this data:
Extract and display settings
Node.js + Express
Adjust your `index.js` file to extract data from the `DATA` header and write it down to the response. Let's create a helper function to extract the data from the header and use it in our endpoint:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
PHP
Create a `public/index.php` file with such content:1 2 3 4 5 6 |
|
Now, when we log in into docupike and call some add-on URL (for example, /a/your-company/myapp/
), we will see the response:
1 2 3 4 |
|
This way, you can adjust the behavior of your service according to the user's needs.
Set the settings#
If you want to let users change the settings, you can create an own settings page like it's described in Frontend part and use frontend API to store the values:
1 2 3 4 5 6 7 8 |
|
If you want to set the setting via backend of the add-on, you should use service API calls.
Let's create some end points to manipulate the settings:
Set random value for counter setting
Node.js + Express
Let's add a new endpoint `/random` that will make an API call to set a random number to counter. Install the library to make a call:1 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
PHP
Let's make a call using cURL. Put the following content into `public/index.php`:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
Now, when we call /a/your-company/myapp/random
, the setting is changed, so when we call /a/your-company/myapp/
again, we see the updated value.