index.js 1.9 KB

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