1

I am working on a gatsby site. In that I have to get configuration related values from variables which are declared in platform.sh variable.

I have tried following approach to read value from platform.sh:

    const { env } = process;

// Utility to assist in decoding a packed JSON variable.
function read_base64_json(varName) {
  try {
    return JSON.parse(Buffer.from(env[varName], "base64").toString());
  } catch (err) {
    throw new Error(`no ${varName} environment variable`);
  }
};

// A simple variable.
let projectId = env.PLATFORM_PROJECT;

// A JSON-encoded value.
let variables = read_base64_json('PLATFORM_VARIABLES');

but it always returns an empty object in PLATFORM_VARIABLES .

Another approach:

I have also tried platformsh-config npm In that I tried to get value using following code:

    const config = require('platformsh-config').config();
    
    // A JSON-encoded value.
    let variables =config.variables();

but it also returns an empty object

James Z
  • 12,209
  • 10
  • 24
  • 44

0 Answers0