index.js 1.7 KB

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