Splitted the node server in modules

This commit is contained in:
Gaël Métais
2014-08-07 19:26:58 +02:00
parent 9b6b0f39f0
commit 7fcdf2aaa2
17 changed files with 407 additions and 250 deletions
+41
View File
@@ -0,0 +1,41 @@
/**
* The page that dispays the results
*/
var async = require('async');
var fs = require ('fs');
var resultsController = function(req, res) {
'use strict';
var testId = req.params.testId;
var resultsPath = 'results/' + testId;
var phantomasResultsPath = resultsPath + '/results.json';
console.log('Opening test ' + testId + ' results as HTML');
async.parallel({
htmlTemplate: function(callback) {
fs.readFile('./app/node_views/results.html', {encoding: 'utf8'}, callback);
},
phantomasResults: function(callback) {
fs.readFile(phantomasResultsPath, {encoding: 'utf8'}, callback);
}
}, function(err, results) {
if (err) {
console.log(err);
return res.status(404).send('Sorry, test not found...');
}
var html = results.htmlTemplate;
html = html.replace('%%RESULTS%%', results.phantomasResults);
res.setHeader('Content-Type', 'text/html');
res.send(html);
});
};
module.exports = resultsController;