Multiple settings import at runtime

Just wondering if there is a way to import 2 setting files on starting up meteor? I want to have 1 with system configuration options for dev, staging and live (checked into git) and another with some passwords in it (not checked into git). The run command only allows --settings to be called once and prevents startup when 2 are passed.

The only way I can see to do it is to use gulp to concatenate them together and not check the concatenated json into the reposititory. Does anyone have an alternative pattern?

Have you considered storing your secret values in the database, and loading them into Meteor.settings when your application starts? This way you don’t have to worry about accidentally committing them. Here’s a quick example of how this could work:

  1. meteor create secret-settings
  2. settings.json in your project root:
{
  "public": {
    "setting1": "Some awesome public setting!"
  },
  "private": {
    "setting1": "Some awesome private setting!"
  }
}
  1. /imports/api/secret_settings/server/collection.js
import { Mongo } from 'meteor/mongo';
const secretSettings = new Mongo.Collection('secret_settings');
export default secretSettings;
  1. /imports/startup/server/seed.js
import secretSettings from '/imports/api/secret_settings/server/collection.js';

// Adding some dummy secrets
if (secretSettings.find().count() === 0) {
  secretSettings.insert({
    key: 'secretSetting1',
    value: 'Some super secret value!'
  });
}
  1. /imports/startup/server/setup_environment.js
import { Meteor } from 'meteor/meteor';
import secretSettings from '/imports/api/secret_settings/server/collection.js';

const privateSettings = Meteor.settings.private;
privateSettings.secret = {};
secretSettings.find().forEach((secretSetting) => {
  privateSettings.secret[secretSetting.key] = secretSetting.value;
});

// You'll see that your database stored secret items are now part of `Meteor.settings`
console.log(Meteor.settings.private.secret.secretSetting1);
  1. /imports/startup/server/index.js
import './seed.js';
import './setup_environment.js';
  1. /server/main.js
import '/imports/startup/server';

I know this is an old thread, but the public values are not made available into Meteor.settings.public
Any ideas how to do that also?

It sounds like you may have an error in your JSON. Can you share a (sanitized) version?

No error in the JSON.
I’m loading the config with --settings=settings.json and refactoring now to load it from the DB.
In the server everything loads ok, including the public key…
But in the Client it’s not available.

The public settings are built into the HTML for the client through the __meteor_runtime_config__ variable. If you’re not using --settings, then that won’t happen. You’ll need to get them via a Meteor method or pub/sub.

Ohhh… I see…
Thank you for the clarifications.