index.js 2.3 KB

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