3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 20:22:39 +01:00
dbot/modules/web.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2011-09-13 22:23:46 +02:00
var express = require('express');
var webInterface = function(dbot) {
var dbot = dbot;
2011-09-13 22:55:20 +02:00
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');
2011-09-13 22:23:46 +02:00
app.get('/', function(req, res) {
res.render('index', { });
});
2011-09-15 13:30:52 +02:00
app.get('/quotes/:key', function(req, res) {
2011-09-15 13:34:01 +02:00
var key = req.params.key.toLowerCase();
if(dbot.db.quoteArrs.hasOwnProperty(key)) {
res.render('quotes', { 'quotes': dbot.db.quoteArrs[key] });
2011-09-15 13:30:52 +02:00
} else {
res.render('error', { 'message': 'No quotes under that key.' });
}
});
2011-09-13 22:23:46 +02:00
2011-09-15 20:56:50 +02:00
app.get('/quotes', function(req, res) {
2011-09-15 13:51:54 +02:00
res.render('quotelist', { 'quotes': Object.keys(dbot.db.quoteArrs) });
2011-09-15 13:50:40 +02:00
});
2011-10-06 01:32:28 +02:00
app.listen(443);
2011-09-14 18:24:32 +02:00
return {
'onDestroy': function() {
2011-09-14 18:46:59 +02:00
app.close();
2011-09-14 18:24:32 +02:00
}
};
2011-09-13 22:23:46 +02:00
};
exports.fetch = function(dbot) {
return webInterface(dbot);
};