index.js 1.7 KB

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