Home Reference Source Repository

src/app/shared/universal-config.js

const universalConfig = () => {
    if (typeof window !== 'undefined') {
        return {
            rocConfig: window.ROC_CONFIG,
            appConfig: window.APP_CONFIG
        };
    }

    const rocConfig = require('roc').getSettings();
    const appConfig = rocConfig.runtime.configWhitelistProperty ?
        require('config')[rocConfig.runtime.configWhitelistProperty] :
        undefined;

    return {
        rocConfig,
        appConfig
    };
}();

/**
 * Universal Configuration Manager
 *
 * Manages both __application__ configuration and __Roc__ configuration.
 * On the server the configurations will be fetched directly and on the client it's expected that the configuration
 * is available on `window` as `ROC_CONFIG` and `APP_CONFIG`.
 *
 * appConfig will only contain what has been selected by `runtime.configWhitelistProperty`. That means if you want
 * to read the full configuration on the server you will need to read it directly from node-config.
 */
export default universalConfig;