var Connect = require('connect'); var http = require('http'); var url = require('url'); var path = require('path'); var fs = require('fs'); var configuration; var model; exports.setModel = function(m) { model = m; }; exports.start = function(config) { configuration = config; Connect.createServer( Connect.logger(), // Log responses to the terminal using Common Log Format. Connect.responseTime(), // Add a special header with timing information. Connect.staticCache(), Connect.static(path.join(__dirname, configuration.dir)), function(req, res) { var purl = url.parse(req.url, true); var slideset = 'default'; if(purl['query'].hasOwnProperty('slides')) { slideset = purl['query']['slides']; } model.getSlides(slideset, function(slides) { fs.readFile(path.join(__dirname, configuration.dir, slides['template']) , function(err,data) { if(err) { res.end(body); } var body = data.toString(); var slideStr = ''; for(var slide in slides['slides']) { if(!slides['slides'].hasOwnProperty(slide)) { continue; } if(slides['slides'][slide]['type'] === 'image') { slideStr = slideStr +'