[FAQ] Custom Environment Variables Not Accessible via iodesktop.env

Problem

I’ve set custom environment variables in the gilding.json configuration file (9.x) and the platform log confirms the configuration file is read successfully. However, when I try to access the custom variables programmatically at runtime via the iodesktop.env object, they do not appear.

Solution

An app must have "allowEnvVars": true in its app definition before the variables are exposed through iodesktop.env. Without this property, the iodesktop.env object will not contain the expected variables for that app.

Example app definition for adding "allowEnvVars": true to the "details" section.

{
    "name": "my-app",
    "title": "My App",
    "type": "window",
    "details": {
        "url": "https://example.com",
        "allowEnvVars": true
    }
}

After adding this property, all available environment variables, including custom ones defined via "envVars" > "set" will be accessible on the iodesktop.env object for that specific app (see Environment Variables – Configuration in the official documentation).

To verify, open the developer console of the specific app whose definition contains "allowEnvVars": true and inspect iodesktop.env:

console.log(iodesktop.env);

Where Custom Environment Variables Are Defined

io.Connect Desktop 9.x

Custom environment variables are defined in the gilding.json configuration file using the "envVars" > "set" property:

{
    "envVars": {
        "set": {
            "MY_APP_PROD": "https://my-app.com",
            "MY_APP_DEV": "https://dev.my-app.com"
        }
    }
}

io.Connect Desktop 10.x

In the 10.x stream (starting 10.0.3) custom environment variables are defined in the system.json system configuration file using the same "envVars" > "set" property:

{
    "envVars": {
        "set": {
            "MY_APP_PROD": "https://my-app.com",
            "MY_APP_DEV": "https://dev.my-app.com"
        }
    }
}

The gilding.json file is relevant only for the 9.0 version stream.