index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 stations = require('./logic/stations');
  8. const cache = require('./logic/cache');
  9. const notifications = require('./logic/notifications');
  10. const config = require('config');
  11. async.waterfall([
  12. // setup our Redis cache
  13. (next) => {
  14. cache.init(config.get('redis').url, () => {
  15. // load some test stations into the cache
  16. /*async.waterfall([
  17. (next) => cache.hset('stations', 'edm', cache.schemas.station({
  18. name: 'edm',
  19. genres: ['edm'],
  20. type: 'official',
  21. displayName: 'EDM',
  22. description: 'EDM Music',
  23. playlist: [
  24. 'gCYcHz2k5x0'
  25. ],
  26. currentSong: {
  27. id: 'gCYcHz2k5x0',
  28. title: 'Title',
  29. artists: ['Artist1'],
  30. genres: ['edm', 'pop'],
  31. thumbnail: 'test',
  32. duration: 100,
  33. skipDuration: 10,
  34. likes: 0,
  35. dislikes: 0
  36. }
  37. }), next),
  38. (next) => cache.hset('stations', 'chill', cache.schemas.station({
  39. name: 'chill',
  40. genres: ['chill'],
  41. type: 'official',
  42. displayName: 'Chill',
  43. description: 'Chill Music',
  44. playlist: [
  45. 'gCYcHz2k5x0'
  46. ]
  47. }), next),
  48. ], next);*/
  49. next();
  50. });
  51. },
  52. // setup our MongoDB database
  53. (next) => db.init(config.get("mongo").url, next),
  54. // setup the express server (not used right now, but may be used for OAuth stuff later, or for an API)
  55. (next) => app.init(next),
  56. // setup the socket.io server (all client / server communication is done over this)
  57. (next) => io.init(next),
  58. // setup the notifications
  59. (next) => notifications.init(config.get('redis').url, next),
  60. // setup the stations
  61. (next) => stations.init(next),
  62. // setup the frontend for local setups
  63. (next) => {
  64. if (!config.get("isDocker")) {
  65. const express = require('express');
  66. const app = express();
  67. const server = app.listen(8080);
  68. app.use(express.static(__dirname + "/../frontend/build/"));
  69. }
  70. next();
  71. }
  72. ], (err) => {
  73. if (err && err !== true) {
  74. console.error('An error occurred while initializing the backend server');
  75. console.error(err);
  76. } else {
  77. console.log('Backend server has been successfully started');
  78. }
  79. });