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.

58 lines
1.4 KiB

  1. 'use strict'
  2. /* global winston */
  3. const fs = require('fs')
  4. const yaml = require('js-yaml')
  5. const _ = require('lodash')
  6. /**
  7. * Load Application Configuration
  8. *
  9. * @param {Object} confPaths Path to the configuration files
  10. * @return {Object} Application Configuration
  11. */
  12. module.exports = (confPaths) => {
  13. confPaths = _.defaults(confPaths, {
  14. config: './config.yml',
  15. data: './app/data.yml'
  16. })
  17. let appconfig = {}
  18. let appdata = {}
  19. try {
  20. appconfig = yaml.safeLoad(fs.readFileSync(confPaths.config, 'utf8'))
  21. appdata = yaml.safeLoad(fs.readFileSync(confPaths.data, 'utf8'))
  22. } catch (ex) {
  23. winston.error(ex)
  24. process.exit(1)
  25. }
  26. // Merge with defaults
  27. appconfig = _.defaultsDeep(appconfig, appdata.defaults.config)
  28. // List authentication strategies
  29. if (appdata.capabilities.manyAuthProviders) {
  30. appconfig.authStrategies = {
  31. list: _.filter(appconfig.auth, ['enabled', true]),
  32. socialEnabled: (_.chain(appconfig.auth).omit('local').reject({ enabled: false }).value().length > 0)
  33. }
  34. if (appconfig.authStrategies.list.length < 1) {
  35. winston.error(new Error('You must enable at least 1 authentication strategy!'))
  36. process.exit(1)
  37. }
  38. } else {
  39. appconfig.authStrategies = {
  40. list: { local: { enabled: true } },
  41. socialEnabled: false
  42. }
  43. }
  44. return {
  45. config: appconfig,
  46. data: appdata
  47. }
  48. }