3d-interface/server/lib/posts.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-05-05 11:56:35 +02:00
/**
* Module dependencies.
*/
var express = require('express');
var fs = require('fs');
2015-07-07 09:27:03 +02:00
var Log = require('./NodeLog.js');
2015-05-05 11:56:35 +02:00
2015-07-07 09:27:03 +02:00
module.exports = function(parent){
2015-07-07 09:27:03 +02:00
Log.debug("Loading controllers :");
fs.readdirSync(__dirname + '/../posts').forEach(function(name){
2015-05-05 11:56:35 +02:00
// index.js in controller, with function as pages (views.py for django)
var obj = require('./../posts/' + name + '/index');
2015-05-05 11:56:35 +02:00
// urls.js, just like django urls.py
var urls = require('./../posts/' + name + '/urls');
name = obj.name || name;
2015-05-05 11:56:35 +02:00
var app = express();
// allow specifying the view engine
if (obj.engine) app.set('view engine', obj.engine);
app.set('views', __dirname + '/../posts/' + name + '/views');
2015-05-05 11:56:35 +02:00
// generate routes based
// on the exported methods
2015-07-07 09:27:03 +02:00
Log.debug(' ' + name + ':');
2015-05-05 11:56:35 +02:00
for (var key in urls) {
2015-07-23 17:19:53 +02:00
app.post(key, obj[urls[key]]);
2015-07-23 17:19:53 +02:00
Log.debug(' ' + key + ' -> ' + name + '.' + urls[key]);
2015-05-05 11:56:35 +02:00
}
2015-07-07 09:27:03 +02:00
Log.debug();
2015-05-05 11:56:35 +02:00
// mount the app
parent.use(app);
});
};