Created
August 10, 2012 14:51
-
-
Save mattmcmanus/3314759 to your computer and use it in GitHub Desktop.
Node Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
stylus = require('stylus'), | |
nib = require('nib'), | |
gzip = require('connect-gzip'), | |
express = require('express'), | |
MongoStore = require('connect-mongo')(express), | |
settings = require('./settings'); | |
module.exports = function(app, at, express) { | |
app.set('environment', settings.NODE_ENV); | |
// Settings | |
app.set("hostname", settings[settings.NODE_ENV].hostname); | |
app.set('db-uri', settings[settings.NODE_ENV].dbUri); | |
// Forms & Sessions | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(express.cookieParser()); | |
app.use(express.session({ secret: '****', store: new MongoStore({ url: settings[settings.NODE_ENV].dbUri }) })); | |
// Set some global defaults | |
app.set("view engine", "jade"); | |
app.use(stylus.middleware({ | |
src: settings.publicDir, | |
compile: function compile(str, path) { | |
return stylus(str) | |
.set('filename', path) | |
//.set('warn', true) | |
.set('compress', true) | |
.use(nib()); | |
//.import('nib'); | |
} | |
})); | |
// Static Files | |
app.use(gzip.staticGzip(settings.publicDir, { maxAge: 1000 * 60 * 60 * 24 * 365 })); | |
app.use(gzip.gzip()); | |
// Development | |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
app.configure('development', function() { | |
// Logging | |
app.use(express.logger('dev')); | |
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | |
}); | |
// Production | |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
app.configure('production', function() { | |
// Logging | |
app.use(express.logger({stream: fs.createWriteStream('./logs/access.log', {flags: 'a'})})); | |
app.use(express.errorHandler()); | |
// Enable view caching | |
app.enable('view cache'); | |
}); | |
// Testing | |
// - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
app.configure('test', function() { | |
app.use(express.logger('dev')); | |
app.use(express.errorHandler({ dumpExceptions: false, showStack: false })); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
// Global Settings | |
// - - - - - - - - - - - - - - - - - - - - - - | |
var settings = { | |
// App Variables | |
name: "Accountable", | |
// Email Settings | |
domain: "accountable.to", | |
from: "[email protected]", | |
email_prefix: "[Accountable] ", | |
// Express Config Variables | |
NODE_ENV : global.process.env.NODE_ENV || 'development', | |
root : path.dirname(__dirname), | |
publicDir : path.join(path.dirname(__dirname), 'public'), | |
port : 8000, | |
apiKeys: { | |
postmark : 'xxxx' | |
} | |
}; | |
// Development | |
// - - - - - - - - - - - - - - - - - - - - - - | |
settings.development = { | |
hostname: 'http://local.host:'+settings.port, | |
dbUri: 'mongodb://localhost/accountable-dev' | |
}; | |
// Production | |
// - - - - - - - - - - - - - - - - - - - - - - | |
settings.production = { | |
hostname: 'http://accountable.to', | |
dbUri: 'mongodb://localhost/accountable-prod' | |
}; | |
// Test | |
// - - - - - - - - - - - - - - - - - - - - - - | |
settings.test = { | |
hostname: 'http://accountable.to:'+settings.port, | |
dbUri: 'mongodb://localhost/accountable-test' | |
}; | |
module.exports = settings; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment