Skip to content

Instantly share code, notes, and snippets.

@kmiyashiro
Created June 10, 2012 21:59
Show Gist options
  • Save kmiyashiro/2907474 to your computer and use it in GitHub Desktop.
Save kmiyashiro/2907474 to your computer and use it in GitHub Desktop.
App
/**
* Module dependencies.
*/
var express = require('express'),
fs = require('fs');
var app = module.exports = express.createServer();
var port = (app.settings.env == 'test') ? 8000 : 3001;
// Configuration
require('./config').config(app);
// Routes
fs.readdir(__dirname + '/routes', function(err, files){
if (err) throw err;
files.forEach(function(file){
require('./routes/' + file.replace('.js',''))(app);
});
// Try to catch all non-matched routes, but fires even if they match routes in ./routes/
app.get(/\/.*/, function(req, res, next) {
res.render('index', {
title: 'BandTape'
});
});
});
app.listen(process.env.app_port || port);
app.on('listening', function() {
console.log("Express server listening on port %d in %s mode",
app.address().port, app.settings.env);
});
exports.config = function(app) {
app.use(express.cookieParser());
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.favicon(__dirname + '/public/favicon.ico', {
maxAge: 2592000000
}));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment