var path = require('path'); var fs = require('fs'); var model; exports.setModel = function(m) { model = m; }; exports.start = function(config) { config.app.get('/slides/:id', function(req, res) { var slideset; slideset = req.params.id; model.getSlides(slideset, function(err, slides) { if(err) { throw err; } fs.readFile(path.join(__dirname, config.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 +'
  • '; } if(slides['slides'][slide]['text'].length > 0) { slideStr = slideStr+'

    '+slides['slides'][slide]['head']+' - '+slides['slides'][slide]['text']+'

  • '; } } var eventStr = ''; for(var date in slides['events']) { eventStr = eventStr + '

    '+date+'


    '; } body = body.replace("$IMAGES", slideStr); body = body.replace("$EVENTS", eventStr); res.setHeader('Content-Length', body.length); res.end(body); }); }); }); config.app.get('*', function(req, res){ model.getAllSlides(function(slidesets) { var body = '

    Slideshows:

    '; for(var slideset in slidesets) { if(!slidesets.hasOwnProperty(slideset)) { continue; } body = body + ''+slidesets[slideset]+'
    '; } res.setHeader('Content-Length', body.length); res.end(body); }); }); config.app.listen(8080); };