3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 22:39:26 +01:00
dbot/modules/web.js
Luke Slater fd4c2e8148 443?
2011-10-06 00:32:28 +01:00

42 lines
1.0 KiB
JavaScript

var express = require('express');
var webInterface = function(dbot) {
var dbot = dbot;
var pub = '../public';
var app = express.createServer();
app.use(express.compiler({ src: pub, enable: ['sass'] }));
app.use(express.static(pub));
app.set('view engine', 'jade');
app.get('/', function(req, res) {
res.render('index', { });
});
app.get('/quotes/:key', function(req, res) {
var key = req.params.key.toLowerCase();
if(dbot.db.quoteArrs.hasOwnProperty(key)) {
res.render('quotes', { 'quotes': dbot.db.quoteArrs[key] });
} else {
res.render('error', { 'message': 'No quotes under that key.' });
}
});
app.get('/quotes', function(req, res) {
res.render('quotelist', { 'quotes': Object.keys(dbot.db.quoteArrs) });
});
app.listen(443);
return {
'onDestroy': function() {
app.close();
}
};
};
exports.fetch = function(dbot) {
return webInterface(dbot);
};