Best Practice to Store ConfigurationĀ
This guide proposes the best practice on how to keep the environment or environment-related keys outside of the project across multiple environments.
Create a new project titled āConfigurationā within each environment (Dev, Stage, Prod). This is the project that we will not be moving whenever publishing our real project.
Open the Configuration project.
Under Develop > Schema create a new Schema and a name for it. In this example, we will name it āSettings.ā We will set it as dynamic data with one field.
This will hold the key value pair between Dev, Stage, and Production.
Now we will go to Report > Data > Settings > and create a content block and a name for it. For this example, we will call it āSettings A.ā
This is the key value pair we will keep here and what we will keep the same across all of the environments.
You can add as many key values here as you want.
Now we need to make sure this Configuration project is created with all of the same Schema and Data settings we have just created across Dev, Stage, and Production.
The key is very important - we need to keep the same key across all of the same environments.
To use it, letās go into Experience Designer of the project you are trying to set up and we will be adding in the following nodes.
Add an Inject node and set it to after 0.1 as we want it to be loaded as fast as possible.
Then add a Function node and name it āSet Model." Set the key to the schema key
Add a Dynamic Data Manager node and program into the Settings
Make sure the content name is the sameĀ as the one we have created
Add another Function node and title it āSet to Global context.ā This is where we will set Settings into the Global context for Experience Designer
We recommend only one settings content so that the below code will only return one. Otherwise, make sure the correct settings item name is used.
var settings = _.get(msg, 'data.dynamicData.result[0].payload', {});
We will create a key in global setting called āConfig Settingā and store the settings that we have to retrieve so that we can use it whenever we need to.
global.set("CONFIG_SETTING", settings);
Letās test it to see if it is working. Insert an Inject node and a Function node to Check Config.
Now when we click on this, it will pull the settings weāve created as part of the content under the settings we have created within the Configuration project.
If you change the settings within the Configuration project, it will only display if you deploy the global context again.
Ā