Skip to content

Instantly share code, notes, and snippets.

@getchenge
Last active August 29, 2015 14:02
Show Gist options
  • Save getchenge/b82984c077b5ce5bc6c9 to your computer and use it in GitHub Desktop.
Save getchenge/b82984c077b5ce5bc6c9 to your computer and use it in GitHub Desktop.
express config
'use strict';
var express = require('express'),
favicon = require('static-favicon'),
logger = require('morgan'),//loging middleware
compression = require('compression'),
bodyParser = require('body-parser'),//urlencoded json
methodOverride = require('method-override'),//enable http verbs on client
cookieParser = require('cookie-parser'),
session = require('express-session'),
errorHandler = require('errorhandler'),
path = require('path'),
config = require('./config'),
dust = require('dustjs-linkedin'),
cons = require('consolidate');
/**
* Express configuration
*/
module.exports = function(app) {
var env = app.get('env');
if ('development' === env) {
// app.use(require('connect-livereload')());
// Disable caching of scripts for easier testing
app.use(function noCache(req, res, next) {
if (req.url.indexOf('/scripts/') === 0) {
res.header('Cache-Control', 'no-cache, no-store, must-revalidate');
res.header('Pragma', 'no-cache');
res.header('Expires', 0);
}
next();
});
app.use(express.static(path.join(config.root, 'app')));
app.set('views', config.root + '/app/views');
}
if ('production' === env) {
app.use(compression());
app.use(favicon(path.join(config.root, 'public', 'favicon.ico')));
app.use(express.static(path.join(config.root, 'public')));
app.set('views', config.root + '/views');
}
app.engine('dt',cons.dust);
cons.dust.helpers = require('dustjs-helpers');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(logger('dev'));
app.use(bodyParser());
app.use(methodOverride());
app.use(cookieParser());
app.use(session({
secret: 'a secret'
// , cookie: { secure: true }
}))
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment