diff --git a/lib/app.js b/lib/app.js index d7a57fa..1f291c9 100644 --- a/lib/app.js +++ b/lib/app.js @@ -1,7 +1,7 @@ var express = require('express') , app = express.createServer() , db = require('./db').db - , config = require('./config').load() + , config = require('./config') , MongoStore = require('connect-mongodb'); ; diff --git a/lib/boot.js b/lib/boot.js index 337852b..d0a5932 100644 --- a/lib/boot.js +++ b/lib/boot.js @@ -1,10 +1,12 @@ // dependencies for initial app load +require('./log'); // use spawn inheritance require('./spawn'); +// custom logging lib = {}; -var config = require('./config').load() +var config = require('./config') , fs = require('fs') , app = require('./app') , plugins = fs.readdirSync(__dirname + '/plugins') diff --git a/lib/config.js b/lib/config.js index 9f125ed..a3814b6 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,23 +1,11 @@ var CONFIG_PATH = './config/' , fs = require('fs') - , cache = {}; - -exports.load = function(path) { - var data = fs.readFileSync(CONFIG_PATH + (path || (path = 'app.json'))) - , json = cache[path] || (cache[path] = JSON.parse(data)) - , bootedJSON = bootParams() - ; - - if(bootedJSON) { - for(var key in bootedJSON) { - if(bootedJSON.hasOwnProperty(key)) { - json[key] = bootedJSON[key]; - } - } - } - - return json; -}; + , util = require('util') + , cache = {} + , data = fs.readFileSync(CONFIG_PATH + 'app.json') + , json =JSON.parse(data) + , bootedJSON = bootParams() +; function bootParams() { for(var i = 0; i < process.argv.length; i++) { @@ -27,4 +15,19 @@ function bootParams() { return JSON.parse(val.substr(3, val.length - 1)); } } -} \ No newline at end of file +} + +if(bootedJSON) { + for(var key in bootedJSON) { + if(bootedJSON.hasOwnProperty(key)) { + json[key] = bootedJSON[key]; + } + } +} + +var log = 'Configuration \n' + + util.inspect(json); + +console.log(log); + +module.exports = json; \ No newline at end of file diff --git a/lib/db.js b/lib/db.js index c0d11c3..f2c9579 100644 --- a/lib/db.js +++ b/lib/db.js @@ -1,4 +1,4 @@ -var config = require('./config').load() +var config = require('./config') , mongodb = require('mongodb') , ObjectID = require('mongodb').BSONPure.ObjectID , connectionString = config['db-host'] + config['db'] diff --git a/lib/model.js b/lib/model.js index 6b2df9f..c117063 100644 --- a/lib/model.js +++ b/lib/model.js @@ -385,7 +385,7 @@ Model = module.exports = emitter.spawn({ collection: _self.collection, name: _self.name || _self.collection }; - } + } delete json._id; _self.description = _self.description || {}; @@ -412,6 +412,8 @@ Model = module.exports = emitter.spawn({ _self.configure(_self.description, function(err) { if(err) console.error(err); }); + + console.info('Updating', _self.name || _self.collection, json); } }) .fetch() @@ -446,6 +448,8 @@ Model = module.exports = emitter.spawn({ } ; + console.info('Defining routes:', model.name || model.collection); + function handler(req, res, next) { var query = req.query , id = req.param('id') diff --git a/lib/plugins/models/index.js b/lib/plugins/models/index.js index 5ae6d6d..3ed7c4c 100644 --- a/lib/plugins/models/index.js +++ b/lib/plugins/models/index.js @@ -7,6 +7,8 @@ var Settings = require('../settings/settings') var models = module.exports.models = {}; var refresh = module.exports.refresh = function() { + + Settings .spawn() .find({plugin: 'models'}) diff --git a/lib/plugins/settings/index.js b/lib/plugins/settings/index.js index ee4317b..842e99f 100644 --- a/lib/plugins/settings/index.js +++ b/lib/plugins/settings/index.js @@ -1,5 +1,5 @@ var app = require('../../app') - , config = require('../../config').load() + , config = require('../../config') , Settings = require('./settings') , Setting = require('./setting') , models = require('../models')