Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[refactor] Migrated configuration system to use nconf library

  • Loading branch information...
commit 5caa8d0afb43fa5d29cc7b8ccde39ae3ac74c926 1 parent 73aca58
@Marak authored
View
103 app/config/application.js
@@ -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: '<strong>Submit a question or comment by posting a tweet to <a href="https://twitter.com/intent/user?screen_name=dftg" title="Design from the Gut on Twitter">@dftg</a> via the button below. Review the submissions and favorite the ones you\'d like to see answered</strong>. The moderator will choose from the top picks.'
- , time: 'Friday, 3/9, 3:30p'
- , location: 'Ballroom BC &bull; 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'
- }
- ]
-}
View
4 app/config/environments/development.js
@@ -1,4 +0,0 @@
-module.exports = {
- database: 'mongodb://'
- , server_port: '3000'
-}
View
4 app/config/environments/production.js
@@ -1,4 +0,0 @@
-module.exports = {
- database: 'mongodb://'
- , server_port: '80'
-}
View
2  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({
View
14 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')
});
}
View
4 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'))
})
View
2  app/services/BaseService.js
@@ -1,5 +1,5 @@
module.exports = Class(function(){
- this.config = app.getConfig()
+ this.config = app.config
})
.methods ({
getModel: function (name) {
View
21 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')
View
84 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": "<strong>Submit a question or comment by posting a tweet to <a href='https://twitter.com/intent/user?screen_name=dftg' title='Design from the Gut on Twitter'>@dftg</a> via the button below. Review the submissions and favorite the ones you\"d like to see answered</strong>. The moderator will choose from the top picks."
+ , "time": "Friday, 3/9, 3:30p"
+ , "location": "Ballroom BC &bull; 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"
+ }
+ ]
+}
View
36 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'))
Please sign in to comment.
Something went wrong with that request. Please try again.