index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. async.waterfall([
  10. // setup our Redis cache
  11. (next) => {
  12. cache.init('redis://redis:6379/0', () => {
  13. // load some test stations into the cache
  14. async.waterfall([
  15. (next) => cache.hset('stations', '7dbf25fd-b10d-6863-2f48-637f6014b162', cache.schemas.station({
  16. name: 'edm',
  17. genres: ['edm'],
  18. displayName: 'EDM',
  19. description: 'EDM Music',
  20. playlist: [
  21. 'gCYcHz2k5x0'
  22. ]
  23. }), next),
  24. (next) => cache.hset('stations', '79cedff1-5341-7f0e-6542-50491c4797b4', cache.schemas.station({
  25. name: 'chill',
  26. genres: ['chill'],
  27. displayName: 'Chill',
  28. description: 'Chill Music',
  29. playlist: [
  30. 'gCYcHz2k5x0'
  31. ]
  32. }), next),
  33. ], next);
  34. });
  35. },
  36. // setup our MongoDB database
  37. (next) => db.init('mongodb://mongo:27017/musare', next),
  38. // setup the express server (not used right now, but may be used for OAuth stuff later, or for an API)
  39. (next) => app.init(next),
  40. // setup the socket.io server (all client / server communication is done over this)
  41. (next) => io.init(next)
  42. ], (err) => {
  43. if (err && err !== true) {
  44. console.error('An error occurred while initializing the backend server');
  45. console.error(err);
  46. }
  47. else {
  48. console.log('Backend server has been successfully started');
  49. }
  50. });