Cody CMS
Fork me on GitHub

Override default settings

On 14 Dec 2014, at 22:29, Marco Monteiro wrote:

The use of "localhost" as the mysql server hsot is hardcoded throughout the source code. It would be great if I could connect to mysql in some other host.

-------

Marco,


When launching a web application in Cody you have to call

function startWebApp(mainServer, config, done);

Where mainServer is an Express server,
done is the function that is called when the Application is ready and running
and conf is an object which can be read with require from a config file or manually filled by you.

I’ve copied the code below from our hosting server, which stores all all settings per site in a database table:

       cody.startWebApp(cody.server, {
            "name": row.name,
            "mailFrom": "info@cody-cms.org",
            “smtp”: "smtpmailer.cody-cms.org",
            "version": row.version,
            "defaultlanguage": row.defaultlanguage,
            "hostnames" : row.hostname,
            "dbuser": row.dbuser,
            "dbpassword": row.dbpassword,
            "dbhost": row.dbhost,
            "datapath": row.datapath,
            "db": row.db,
            "controllers": require("./" + row.name + "/controllers/")
          }, next);


So if the default values are ok for you, you can just start the app with:

       cody.startWebApp(cody.server, 
            { “dbhost”: “your.mysql-host.com” }, 
            function() { console.log(“we’re ready”); } 
       
);



An extract from the default settings, but I agree someone should put these in the readme file:

 
  config.db = config.db || config.name;
  config.version = config.version || "v1.0";
  config.controllers = config.controllers || [];

  config.datapath = config.datapath || ".";

  this.testing = config.testing || config.testing || false;
  this.logging = config.logging || config.logging || true;

  this.defaultlanguage = config.defaultlanguage || config.defaultlanguage || Application.kDefaultLanguage;

  //TODO: don't we have to return errors if some of these are missing ?
  this.name = config.name || "cody";
  this.version =  config.version || "v0.2";
  this.datapath =  config.datapath || "./data";

  this.dbuser = config.dbuser || "cody";
  this.dbpassword = config.dbpassword || "ydoc";
  this.dbhost = config.dbhost || "localhost";
  this.db = config.db || "cody";
  this.smtp = config.smtp || "smtp.telenet.be";
  this.mailFrom = config.mailFrom || "info@cody-cms.org";

  this.dumpStructures = config.dumpstructures || true;

 
Johan Coppieters.