A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

  1. var express = require('express'),
  2. https = require('https');
  3. //---- Construct ----
  4. function WEB(db, options) {
  5. var __self = this;
  6. __self.db = db;
  7. __self.port = options.port || 9000;
  8. __self.title = options.title;
  9. __self.slogan = options.slogan;
  10. __self.logo = options.logo;
  11. __self.twitter = options.twitter;
  12. }
  13. // ---- Methods ----
  14. WEB.prototype.start = function () {
  15. var __self = this;
  16. __self.srv = express();
  17. __self.srv.set('view engine', 'jade');
  18. __self.srv.set('views', 'web/templates');
  19. __self.srv.use(express.static('./web/public'));
  20. // ---- Routes -----
  21. __self.srv.get('/', function(req, res) {
  22. //lets get the top 5
  23. sql = 'SELECT * FROM viewers ORDER BY points DESC LIMIT 10;';
  24. __self.db.execute(sql, function(rows) {
  25. res.render('index', {
  26. title: __self.title,
  27. slogan: __self.slogan,
  28. logo: __self.logo,
  29. twitter: __self.twitter,
  30. rows: rows,
  31. });
  32. });
  33. });
  34. __self.srv.get('/ladder', function(req, res) {
  35. //get the whole viewer list
  36. sql = 'SELECT * FROM viewers ORDER BY points DESC;';
  37. __self.db.execute(sql, function(rows) {
  38. res.render('ladder', {
  39. title: __self.title,
  40. slogan: __self.slogan,
  41. logo: __self.logo,
  42. twitter: __self.twitter,
  43. rows: rows
  44. });
  45. });
  46. });
  47. __self.srv.listen(__self.port);
  48. console.log('Started website at '+__self.port);
  49. };
  50. module.exports = function (db, options) {
  51. return new WEB(db, options);
  52. };