diff --git a/app/config/application.js b/app/config/application.js deleted file mode 100644 index 0d2a927..0000000 --- a/app/config/application.js +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2012 Twitter, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -module.exports = { - - /* - TODO: Change all of the values here with your app's own credentials - Refer to https://github.com/twitter/ospriet/wiki/Customizing-Ospriet for help - */ - - /* Application configuration */ - twitter_app: { - consumer_key: '' - , consumer_secret: '' - , access_token_key: '' - , access_token_secret: '' - } - - , twitter_account: { - id: '495336570' - , screen_name: 'dftg' - } - - , moderators: [ - { - id_str: '18644328' - , screen_name: 'philcoffman' - } - ] - - , blacklist: [ - { - id_str: '' - , screen_name: '' - } - ] - - /* Site/UI configuration */ - , site: { - raw_url: 'http://designfromthegut.com' - , display_url: 'designfromthegut.com' - , google_analytics: 'UA-8533626-2' - } - - , event: { - title: 'Design from the Gut' - , description: 'Debating whether research or intuition is a better approach to design should be a communal discussion.' - , instructions: 'Submit a question or comment by posting a tweet to @dftg via the button below. Review the submissions and favorite the ones you\'d like to see answered. The moderator will choose from the top picks.' - , time: 'Friday, 3/9, 3:30p' - , location: 'Ballroom BC • ACC' - , details_url: 'http://schedule.sxsw.com/2012/events/event_IAP11592' - } - - , participants: [ - { - name: 'Phil Coffman' - , title: 'Principal, Element' - , twitter: 'philcoffman' - , img_url: 'coffman.gif' - , role: 'Moderator' - } - , { - name: 'Bill Couch' - , title: 'Software engineer, Twitter' - , twitter: 'couch' - , img_url: 'couch.gif' - , role: 'Panelist' - } - , { - name: 'Naz Hamid' - , title: 'Principal, Weightshift' - , twitter: 'weightshift' - , img_url: 'hamid.gif' - , role: 'Panelist' - } - , { - name: 'Laurel Hechanova' - , title: 'Designer, Illustrator, Apocalypse OK' - , twitter: 'hechanova' - , img_url: 'hechanova.gif' - , role: 'Panelist' - } - , { - name: 'Jane Leibrock' - , title: 'User Experience Researcher, Facebook' - , twitter: 'fencebreak' - , img_url: 'leibrock.gif' - , role: 'Panelist' - } - ] -} \ No newline at end of file diff --git a/app/config/environments/development.js b/app/config/environments/development.js deleted file mode 100644 index 468b85d..0000000 --- a/app/config/environments/development.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - database: 'mongodb://' - , server_port: '3000' -} \ No newline at end of file diff --git a/app/config/environments/production.js b/app/config/environments/production.js deleted file mode 100644 index 470bcb0..0000000 --- a/app/config/environments/production.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - database: 'mongodb://' - , server_port: '80' -} \ No newline at end of file diff --git a/app/controllers/ApplicationController.js b/app/controllers/ApplicationController.js index 9827ab4..93ed888 100644 --- a/app/controllers/ApplicationController.js +++ b/app/controllers/ApplicationController.js @@ -16,7 +16,7 @@ module.exports = require('matador').BaseController.extend(function () { this.viewFolder = '' this.layout = 'layout' - this.config = app.getConfig() + this.config = app.config }) .methods({ diff --git a/app/controllers/HomeController.js b/app/controllers/HomeController.js index 4319127..371212a 100644 --- a/app/controllers/HomeController.js +++ b/app/controllers/HomeController.js @@ -25,10 +25,10 @@ module.exports = require('./ApplicationController').extend(function () { index: function () { this.render('index', { view: 'index' - , event: this.config.event - , participants: this.config.participants - , screen_name: this.config.twitter_account.screen_name - , site: this.config.site + , event: this.config.get('event') + , participants: this.config.get('participants') + , screen_name: this.config.get('twitter_account:screen_name') + , site: this.config.get('site') , css: [ {url: 'lib/bootstrap/bootstrap-responsive.css'} , {url: 'css/application-responsive.css'} @@ -44,9 +44,9 @@ module.exports = require('./ApplicationController').extend(function () { , display: function () { this.render('display', { view: 'presentation' - , event: this.config.event - , screen_name: this.config.twitter_account.screen_name - , site: this.config.site + , event: this.config.get('event') + , screen_name: this.config.get('twitter_account:screen_name') + , site: this.config.get('site') }); } diff --git a/app/models/ApplicationModel.js b/app/models/ApplicationModel.js index 165fb49..65a5590 100644 --- a/app/models/ApplicationModel.js +++ b/app/models/ApplicationModel.js @@ -17,6 +17,6 @@ module.exports = Class(function () { this.mongo = require('mongodb') this.mongoose = require('mongoose') this.Schema = this.mongoose.Schema - this.config = app.getConfig() - this.mongoose.connect(this.config.database) + this.config = app.config + this.mongoose.connect(this.config.get('database')) }) \ No newline at end of file diff --git a/app/services/BaseService.js b/app/services/BaseService.js index 7f74c14..9cab553 100644 --- a/app/services/BaseService.js +++ b/app/services/BaseService.js @@ -1,5 +1,5 @@ module.exports = Class(function(){ - this.config = app.getConfig() + this.config = app.config }) .methods ({ getModel: function (name) { diff --git a/app/services/StreamService.js b/app/services/StreamService.js index 6ffaab9..9201747 100644 --- a/app/services/StreamService.js +++ b/app/services/StreamService.js @@ -18,30 +18,31 @@ var io = require('socket.io').listen(app) io.set('log level', 1) module.exports = require(app.set('services') + '/BaseService').extend(function () { + this.twttr = new twitter({ - consumer_key: this.config.twitter_app.consumer_key - , consumer_secret: this.config.twitter_app.consumer_secret - , access_token_key: this.config.twitter_app.access_token_key - , access_token_secret: this.config.twitter_app.access_token_secret + consumer_key: this.config.get('twitter_app:consumer_key') + , consumer_secret: this.config.get('twitter_app:consumer_secret') + , access_token_key: this.config.get('twitter_app:access_token_key') + , access_token_secret: this.config.get('twitter_app:access_token_secret') }) this.stream_active = false this.account_details = { - id_str: this.config.twitter_account.id - , screen_name: this.config.twitter_account.screen_name + id_str: this.config.get('twitter_account:id') + , screen_name: this.config.get('twitter_account:screen_name') } this.moderators = [ { - id_str: this.config.twitter_account.id - , screen_name: this.config.twitter_account.screen_name + id_str: this.config.get('twitter_account:id') + , screen_name: this.config.get('twitter_account:screen_name') } ] - v.each(this.config.moderators, function(moderator) { + v.each(this.config.get('moderators'), function(moderator) { this.moderators.push(moderator) }.bind(this)) - this.blacklist = this.config.blacklist + this.blacklist = this.config.get('blacklist') this.account_statuses = [] this.model = this.getModel('Favorites') diff --git a/config.json b/config.json new file mode 100644 index 0000000..b8a3589 --- /dev/null +++ b/config.json @@ -0,0 +1,84 @@ +{ + + "database": "mongo://" + , "server_port": "80" + + , "twitter_app": { + "consumer_key": "", + "consumer_secret": "", + "access_token_key": "", + "access_token_secret": "" + } + + , "twitter_account": { + "id": "495336570" + , "screen_name": "dftg" + } + + , "moderators": [ + { + "id_str": "18644328" + , "screen_name": "philcoffman" + } + ] + + , "blacklist": [ + { + "id_str": "" + , "screen_name": "" + } + ] + + , "site": { + "raw_url": "http://designfromthegut.com" + , "display_url": "designfromthegut.com" + , "google_analytics": "UA-8533626-2" + } + + , "event": { + "title": "Design from the Gut" + , "description": "Debating whether research or intuition is a better approach to design should be a communal discussion." + , "instructions": "Submit a question or comment by posting a tweet to @dftg via the button below. Review the submissions and favorite the ones you\"d like to see answered. The moderator will choose from the top picks." + , "time": "Friday, 3/9, 3:30p" + , "location": "Ballroom BC • ACC" + , "details_url": "http://schedule.sxsw.com/2012/events/event_IAP11592" + } + + , "participants": [ + { + "name": "Phil Coffman" + , "title": "Principal, Element" + , "twitter": "philcoffman" + , "img_url": "coffman.gif" + , "role": "Moderator" + } + , { + "name": "Bill Couch" + , "title": "Software engineer, Twitter" + , "twitter": "couch" + , "img_url": "couch.gif" + , "role": "Panelist" + } + , { + "name": "Naz Hasdamid" + , "title": "Principal, Weightshift" + , "twitter": "weightshift" + , "img_url": "hamid.gif" + , "role": "Panelist" + } + , { + "name": "Laurel Hechanova" + , "title": "Designer, Illustrator, Apocalypse OK" + , "twitter": "hechanova" + , "img_url": "hechanova.gif" + , "role": "Panelist" + } + , { + "name": "Jane Leibrock" + , "title": "User Experience Researcher, Facebook" + , "twitter": "fencebreak" + , "img_url": "leibrock.gif" + , "role": "Panelist" + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 1b033cc..9dcbf75 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "klass": "*", "colors": "*", "hogan.js": "*", - "matador": "<=0.0.14" + "matador": "<=0.0.14", + "nconf": "0.5.1" }, "domains": [ "designfromthegut.com" diff --git a/server.js b/server.js index 1bf880b..94e7f6f 100644 --- a/server.js +++ b/server.js @@ -15,6 +15,7 @@ var matador = require('matador') var fs = require('fs') +var nconf = require('nconf') app.configure(function () { app.set('models', __dirname + '/app/models') @@ -23,29 +24,18 @@ app.configure(function () { app.set('controllers', __dirname + '/app/controllers') app.set('services', __dirname + '/app/services') - // added code - - app.set('config', __dirname + '/app/config') - var configStore = {} - function fetchConfig() { - configStore = require(app.set('config') + '/application') - var env = process.env.NODE_ENV - if (!env) env = 'production' // default to production - var env_config_file = app.set('config') + '/environments/' + env + '.js' - try { - var stat = fs.statSync(env_config_file) - if (!stat.isFile()) return - v.extend(configStore, require(env_config_file)) - } catch (e) { - return - } - } - fetchConfig() - app.getConfig = function () { - return configStore - } + // + // Setup nconf to use (in-order): + // 1. Command-line arguments + // 2. Environment variables + // 3. A file located at 'path/to/config.json' + // + nconf.argv() + .env() + .file({ file: 'config.json' }); + app.config = nconf; var serviceList = ['Stream'] var serviceStore = [] @@ -101,5 +91,5 @@ app.configure('production', function () { }) matador.mount(require('./app/config/routes')) -app.listen(app.getConfig().server_port) -console.log('matador running on port ' + app.getConfig().server_port) +app.listen(app.config.get('server_port')) +console.log('matador running on port ' + app.config.get('server_port'))