Created
September 19, 2012 11:01
-
-
Save ag4ve/3749051 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
info: HTTP GET /favicon.ico httpVersion=1.1, host=localhost:3000, connection=kee | |
p-alive, accept=*/*, user-agent=Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWeb | |
Kit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3, accept-encoding=gz | |
ip,deflate,sdch, accept-language=en-US,en;q=0.8, accept-charset=ISO-8859-1,utf-8 | |
;q=0.7,*;q=0.3, cookie=connect.sid=s%3AfFmx5xTQd%2F1%2Ba1Gcpp%2FB1YrW.UKvZYwo6Dd | |
y7q28fQi3RLXHRP2IxvAf%2FmhYvBGEL6l8, url=/favicon.ico, method=GET, originalUrl=/ | |
favicon.ico, | |
Error: Cannot find module 'undefined' | |
at Function.Module._resolveFilename (module.js:338:15) | |
at Function.Module._load (module.js:280:25) | |
at Module.require (module.js:362:17) | |
at require (module.js:378:17) | |
at new View (/home/swilson/node/fr/node_modules/express/lib/view.js:42:49) | |
at Function.app.render (/home/swilson/node/fr/node_modules/express/lib/appli | |
cation.js:485:12) | |
at ServerResponse.res.render (/home/swilson/node/fr/node_modules/express/lib | |
/response.js:718:7) | |
at Object.handle (/home/swilson/node/fr/app.js:78:13) | |
at next (/home/swilson/node/fr/node_modules/express/node_modules/connect/lib | |
/proto.js:190:15) | |
at pass (/home/swilson/node/fr/node_modules/express/lib/router/index.js:108: | |
24) | |
// app.js | |
// module config | |
var fs = require('fs'), | |
express = require('express'), | |
nconf = require('nconf'), | |
expressWinston = require('express-winston'), | |
winston = require('winston'), | |
ecstatic = require('ecstatic'); | |
var path = __dirname; | |
var app = express(); | |
// TODO need to make winston work as regular logger (as well as middleware) | |
var log = console; | |
// global config data | |
nconf.argv() | |
.env() | |
.file({ file: 'config.json', | |
dir: './' | |
}); | |
// default configuration | |
nconf.defaults({ | |
"env": 'dev', | |
"sSec": 'dlk4b5098cn brBLOIblkj84f;-=38 ,.aBOR', | |
"server": { | |
"host": '127.0.0.1', | |
"port": '3000' | |
}, | |
"mongo": { | |
"host": '127.0.0.1' | |
} | |
}); | |
var logOpts = { | |
transports: [ | |
new winston.transports.Console({ | |
colorize: true | |
}) | |
] | |
}; | |
// end config | |
// START WORK | |
// Initial bootstrapping | |
exports.boot = function(params){ | |
app.settings.nconf = nconf; | |
app.settings.log = log; | |
// Bootstrap application | |
bootApplication(app); | |
boot(app, 'model'); | |
// boot(app, 'view'); | |
boot(app, 'controller'); | |
return app; | |
}; | |
function bootApplication (app) { | |
// log parms | |
var winsMid = expressWinston.logger(logOpts); | |
// launch | |
app.use(express.favicon()); | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(express.cookieParser()); | |
app.use(express.session({ secret: nconf.get('sSec') })); | |
app.use(ecstatic(path + '/public')); // Before router to enable dynamic rou | |
ting | |
app.use(winsMid); | |
app.use(app.router); | |
app.use(winsMid); | |
}; | |
// Bootstrap controllers | |
function boot (app, part) { | |
fs.readdir(path + '/' + part, function(err, files){ | |
if (err) throw err; | |
files.forEach(function(file){ | |
if (file.match(/.*\\.js$/)) { | |
bootPart(app, part, file); | |
} | |
}); | |
}); | |
}; | |
function bootPart (app, part, file) { | |
// container_name => object | |
// ie, v_index | |
var cname = part.substr(0,1); | |
var obj = require(path + '/' + part + '/'+ file); | |
app.settings[cname + '_' + file.replace('.js', '')] = obj.init(app); | |
} | |
var server = nconf.get('server'); | |
// allow normal node loading if appropriate | |
if (!module.parent) { | |
exports.boot().listen(server.port, server.host); | |
log.log("Express server %s listening on http://%s:%s", | |
express.version, nconf.get('server:host'), nconf.get('server:port')) | |
; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment