index.js 1.8 KB

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