Changed files to clean

This commit is contained in:
Thomas FORGIONE 2015-05-19 11:12:38 +02:00
parent ee3bf01ab0
commit 571d4b3167
3 changed files with 45 additions and 30 deletions

38
lib/controllers.js Normal file
View File

@ -0,0 +1,38 @@
/**
* Module dependencies.
*/
var express = require('express');
var fs = require('fs');
module.exports = function(parent, options){
var verbose = options.verbose;
fs.readdirSync(__dirname + '/../posts').forEach(function(name){
// index.js in controller, with function as pages (views.py for django)
var obj = require('./../posts/' + name + '/index');
// urls.js, just like django urls.py
var urls = require('./../posts/' + name + '/urls');
var name = obj.name || name;
var app = express();
// allow specifying the view engine
if (obj.engine) app.set('view engine', obj.engine);
app.set('views', __dirname + '/../posts/' + name + '/views');
// generate routes based
// on the exported methods
verbose && console.log('\t' + name + ':');
for (var key in urls) {
app.post(key, obj[urls[key]]);
console.log('\t\t' + key + ' -> ' + name + '.' + urls[key]);
}
console.log();
// mount the app
parent.use(app);
});
};

View File

@ -34,32 +34,4 @@ module.exports = function(parent, options){
// mount the app // mount the app
parent.use(app); parent.use(app);
}); });
fs.readdirSync(__dirname + '/../posts').forEach(function(name){
// index.js in controller, with function as pages (views.py for django)
var obj = require('./../posts/' + name + '/index');
// urls.js, just like django urls.py
var urls = require('./../posts/' + name + '/urls');
var name = obj.name || name;
var app = express();
// allow specifying the view engine
if (obj.engine) app.set('view engine', obj.engine);
app.set('views', __dirname + '/../posts/' + name + '/views');
// generate routes based
// on the exported methods
verbose && console.log('\t' + name + ':');
for (var key in urls) {
app.post(key, obj[urls[key]]);
console.log('\t\t' + key + ' -> ' + name + '.' + urls[key]);
}
console.log();
// mount the app
parent.use(app);
});
}; };

View File

@ -35,13 +35,18 @@ app.use(function(req, res, next) {
res.locals.alertCookie = false; res.locals.alertCookie = false;
} else { } else {
res.locals.alertCookie = true; res.locals.alertCookie = true;
res.cookie('alreadyCame', true); res.cookie('alreadyCame', true, {maxAge: 604800000}); // One week in ms
} }
next(); next();
}); });
// Load controllers // Load controllers
require('./lib/boot')(app, { verbose: !module.parent }); console.log("Loading controllers :");
require('./lib/controllers')(app, { verbose: !module.parent });
// Load post to log data from user study
console.log("Loading posts :");
require('./lib/posts')(app, { verbose: !module.parent });
app.use('/static', express.static('static')); app.use('/static', express.static('static'));