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.

56 lines
1.3 KiB

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