index.js 1.8 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 cache = require('./logic/cache');
  8. const config = require('config');
  9. async.waterfall([
  10. // setup our Redis cache
  11. (next) => {
  12. cache.init(config.get('redis').url, () => {
  13. // load some test stations into the cache
  14. async.waterfall([
  15. (next) => cache.hset('stations', '7dbf25fd-b10d-6863-2f48-637f6014b162', cache.schemas.station({
  16. name: 'edm',
  17. genres: ['edm'],
  18. displayName: 'EDM',
  19. description: 'EDM Music',
  20. playlist: [
  21. 'gCYcHz2k5x0'
  22. ]
  23. }), next),
  24. (next) => cache.hset('stations', '79cedff1-5341-7f0e-6542-50491c4797b4', cache.schemas.station({
  25. name: 'chill',
  26. genres: ['chill'],
  27. displayName: 'Chill',
  28. description: 'Chill Music',
  29. playlist: [
  30. 'gCYcHz2k5x0'
  31. ]
  32. }), next),
  33. ], next);
  34. });
  35. },
  36. // setup our MongoDB database
  37. (next) => db.init(config.get("mongo").url, next),
  38. // setup the express server (not used right now, but may be used for OAuth stuff later, or for an API)
  39. (next) => app.init(next),
  40. // setup the socket.io server (all client / server communication is done over this)
  41. (next) => io.init(next),
  42. // setup the frontend for local setups
  43. (next) => {
  44. if (!config.get("isDocker")) {
  45. const express = require('express');
  46. const app = express();
  47. const server = app.listen(8080);
  48. app.use(express.static(__dirname + "/../frontend/build/"));
  49. }
  50. next();
  51. }
  52. ], (err) => {
  53. if (err && err !== true) {
  54. console.error('An error occurred while initializing the backend server');
  55. console.error(err);
  56. }
  57. else {
  58. console.log('Backend server has been successfully started');
  59. }
  60. });