index.js 1.5 KB

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