summaryrefslogtreecommitdiff
path: root/frontend.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend.js')
-rw-r--r--frontend.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/frontend.js b/frontend.js
new file mode 100644
index 0000000..5b2d486
--- /dev/null
+++ b/frontend.js
@@ -0,0 +1,48 @@
+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 +'<li><img src="/'+slides['slides'][slide]['file']+'">';
+ }
+ if(slides['slides'][slide]['text'].length > 0) {
+ slideStr = slideStr+'<div class="transover"><h2>'+slides['slides'][slide]['head']+' - '+slides['slides'][slide]['text']+'</h2></div></img></li>';
+ }
+ }
+ body = body.replace("$IMAGES", slideStr);
+ res.setHeader('Content-Length', body.length);
+ res.end(body);
+ });
+ });
+ }
+ ).listen(8080);
+};