2012-12-24 06:47:47 +01:00
|
|
|
var express = require('express'),
|
|
|
|
fs = require('fs');
|
2012-12-11 17:04:52 +01:00
|
|
|
|
|
|
|
var webInterface = function(dbot) {
|
|
|
|
var pub = 'public';
|
2012-12-24 05:06:04 +01:00
|
|
|
var app = express();
|
2012-12-11 17:04:52 +01:00
|
|
|
|
|
|
|
app.use(express.static(pub));
|
|
|
|
app.set('view engine', 'jade');
|
|
|
|
|
|
|
|
app.get('/', function(req, res) {
|
2012-12-17 18:18:31 +01:00
|
|
|
res.render('index', { 'name': dbot.config.name });
|
2012-12-11 17:04:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-12-24 06:47:47 +01:00
|
|
|
app.listen(dbot.config.web.webPort);
|
2012-12-11 17:04:52 +01:00
|
|
|
|
2012-12-24 06:47:47 +01:00
|
|
|
var reloadPages = function(pages) {
|
|
|
|
for(var p in pages) {
|
|
|
|
if( pages.hasOwnProperty(p) ) {
|
|
|
|
var func = pages[p];
|
|
|
|
var mod = func.module;
|
|
|
|
app.get(p, (function(req, resp) {
|
|
|
|
// Crazy shim to seperate module views.
|
|
|
|
var shim = Object.create(resp);
|
|
|
|
shim.render = (function(view, one, two) {
|
|
|
|
// Render with express.js
|
|
|
|
resp.render(this.module.name + '/' + view, one, two);
|
|
|
|
}).bind(this);
|
|
|
|
shim.render_core = resp.render;
|
|
|
|
this.call(this.module, req, shim);
|
|
|
|
}).bind(func));
|
2012-12-11 17:04:52 +01:00
|
|
|
}
|
|
|
|
}
|
2012-12-24 06:47:47 +01:00
|
|
|
};
|
2012-12-11 17:04:52 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
'name': 'web',
|
|
|
|
'ignorable': false,
|
2012-12-24 06:47:47 +01:00
|
|
|
'reloadPages': reloadPages,
|
2012-12-11 17:04:52 +01:00
|
|
|
|
|
|
|
'onDestroy': function() {
|
|
|
|
app.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return webInterface(dbot);
|
|
|
|
};
|