index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. type: 'official',
  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. type: 'official',
  29. displayName: 'Chill',
  30. description: 'Chill Music',
  31. playlist: [
  32. 'gCYcHz2k5x0'
  33. ]
  34. }), next),
  35. ], next);
  36. });
  37. },
  38. // setup our MongoDB database
  39. (next) => db.init(config.get("mongo").url, next),
  40. // setup the express server (not used right now, but may be used for OAuth stuff later, or for an API)
  41. (next) => app.init(next),
  42. // setup the socket.io server (all client / server communication is done over this)
  43. (next) => io.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(8080);
  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. }
  59. else {
  60. console.log('Backend server has been successfully started');
  61. }
  62. });