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. 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. dataRegex: '../app/regex.js'
  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. appdata.regex = require(confPaths.dataRegex)
  23. } catch (ex) {
  24. console.error(ex)
  25. process.exit(1)
  26. }
  27. // Merge with defaults
  28. appconfig = _.defaultsDeep(appconfig, appdata.defaults.config)
  29. // List authentication strategies
  30. if (appdata.capabilities.manyAuthProviders) {
  31. appconfig.authStrategies = {
  32. list: _.filter(appconfig.auth, ['enabled', true]),
  33. socialEnabled: (_.chain(appconfig.auth).omit('local').reject({ enabled: false }).value().length > 0)
  34. }
  35. if (appconfig.authStrategies.list.length < 1) {
  36. console.error(new Error('You must enable at least 1 authentication strategy!'))
  37. process.exit(1)
  38. }
  39. } else {
  40. appconfig.authStrategies = {
  41. list: { local: { enabled: true } },
  42. socialEnabled: false
  43. }
  44. }
  45. return {
  46. config: appconfig,
  47. data: appdata
  48. }
  49. }