index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 playlists = require('./logic/playlists');
  10. const cache = require('./logic/cache');
  11. const notifications = require('./logic/notifications');
  12. const config = require('config');
  13. async.waterfall([
  14. // setup our Redis cache
  15. (next) => {
  16. cache.init(config.get('redis').url, () => {
  17. next();
  18. });
  19. },
  20. // setup our MongoDB database
  21. (next) => db.init(config.get("mongo").url, next),
  22. // setup the express server (not used right now, but may be used for OAuth stuff later, or for an API)
  23. (next) => app.init(next),
  24. // setup the socket.io server (all client / server communication is done over this)
  25. (next) => io.init(next),
  26. // setup the notifications
  27. (next) => notifications.init(config.get('redis').url, next),
  28. // setup the stations
  29. (next) => stations.init(next),
  30. // setup the songs
  31. (next) => songs.init(next),
  32. // setup the playlists
  33. (next) => playlists.init(next),
  34. // setup the frontend for local setups
  35. (next) => {
  36. if (!config.get("isDocker")) {
  37. const express = require('express');
  38. const app = express();
  39. const server = app.listen(80);
  40. app.use(express.static(__dirname + "/../frontend/build/"));
  41. }
  42. next();
  43. }
  44. ], (err) => {
  45. if (err && err !== true) {
  46. console.error('An error occurred while initializing the backend server');
  47. console.error(err);
  48. } else {
  49. console.info('Backend server has been successfully started');
  50. }
  51. });