index.js 1.8 KB

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