Make static asset caching an option

This commit is contained in:
John Crepezzi 2011-11-21 23:00:28 -05:00
commit 9ed330bdae
4 changed files with 12 additions and 7 deletions

View file

@ -37,6 +37,9 @@ if (!config.storage.type) {
var Store = require('./lib/' + config.storage.type + '_document_store');
var preferredStore = new Store(config.storage);
// Configure a static handler for the static files
var staticHandler = new StaticHandler('./static', !!config.cacheStaticAssets);
// Set the server up and listen forever
http.createServer(function(request, response) {
var incoming = url.parse(request.url, false);
@ -59,8 +62,7 @@ http.createServer(function(request, response) {
return handler.handleGet(match[1], response);
}
// Otherwise, look for static file
handler = new StaticHandler('./static');
handler.handle(incoming.pathname, response);
staticHandler.handle(incoming.pathname, response);
}).listen(config.port, config.host);
winston.info('listening on ' + config.host + ':' + config.port);