1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
};
|