You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2 KiB

  1. "use strict";
  2. var fs = require('fs'),
  3. yaml = require('js-yaml'),
  4. _ = require('lodash');
  5. /**
  6. * Load Application Configuration
  7. *
  8. * @param {String} confPath Path to the configuration file
  9. * @return {Object} Application Configuration
  10. */
  11. module.exports = (confPath) => {
  12. var appconfig = {};
  13. try {
  14. appconfig = yaml.safeLoad(fs.readFileSync(confPath, 'utf8'));
  15. } catch (ex) {
  16. winston.error(ex);
  17. process.exit(1);
  18. }
  19. // Merge with defaults
  20. appconfig = _.defaultsDeep(appconfig, {
  21. title: "Requarks Wiki",
  22. host: "http://localhost",
  23. port: process.env.PORT,
  24. auth: {
  25. local: { enabled: true },
  26. microsoft: { enabled: false },
  27. google: { enabled: false },
  28. facebook: { enabled: false },
  29. },
  30. db: "mongodb://localhost/wiki",
  31. redis: null,
  32. sessionSecret: null,
  33. admin: null
  34. });
  35. // List authentication strategies
  36. appconfig.authStrategies = {
  37. list: _.filter(appconfig.auth, ['enabled', true]),
  38. socialEnabled: (_.chain(appconfig.auth).omit('local').reject({ enabled: false }).value().length > 0)
  39. }
  40. if(appconfig.authStrategies.list.length < 1) {
  41. winston.error(new Error('You must enable at least 1 authentication strategy!'));
  42. process.exit(1);
  43. }
  44. return appconfig;
  45. };