index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. process.env.NODE_CONFIG_DIR = `${__dirname}/config`;
  3. const async = require('async');
  4. const db = require('./logic/db');
  5. const app = require('./logic/app');
  6. const io = require('./logic/io');
  7. const cache = require('./logic/cache');
  8. const scheduler = require('./logic/scheduler');
  9. // setup our cache with the tables we need
  10. cache.addTable('sessions');
  11. cache.addTable('stations');
  12. async.waterfall([
  13. // connect to our database
  14. (next) => db.init('mongodb://mongo:27017/musare', next),
  15. // load all the stations from the database into the cache (we won't actually do this in the future)
  16. (next) => {
  17. // this represents data directly from the DB (for now, lets just add some dummy stations)
  18. let stations = [
  19. {
  20. id: '7dbf25fd-b10d-6863-2f48-637f6014b162',
  21. name: 'edm',
  22. genres: ['edm'],
  23. displayName: 'EDM',
  24. description: 'EDM Music',
  25. playlist: [
  26. 'gCYcHz2k5x0'
  27. ]
  28. },
  29. {
  30. id: '79cedff1-5341-7f0e-6542-50491c4797b4',
  31. genres: ['chill'],
  32. displayName: 'Chill',
  33. description: 'Chill Music',
  34. playlist: [
  35. 'gCYcHz2k5x0'
  36. ]
  37. }
  38. ];
  39. stations.forEach((station) => {
  40. // add the station to the cache, adding the temporary data
  41. cache.addRow('stations', Object.assign(station, {
  42. skips: 0,
  43. userCount: 0,
  44. currentSongIndex: 0,
  45. paused: false
  46. }));
  47. });
  48. next();
  49. },
  50. // setup the express server (not used right now, but may be used for OAuth stuff later, or for an API)
  51. (next) => app.init(next),
  52. // setup the socket.io server (all client / server communication is done over this)
  53. (next) => io.init(next)
  54. ], (err) => {
  55. if (err) return console.error(err);
  56. console.log('Backend has been started');
  57. });