index.js 2.1 KB

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