index.js 1.9 KB

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