summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends/external-backends.js
blob: 0bf891ed028853e281dd41911d56e3ae3199596c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* global __appdir */
const fs = require('fs')
const path = require('path')

class ExternalBackends {
  getBackends () {
    var files = fs.readdirSync(path.join(__appdir, 'lib', 'external-backends', 'backends'))
    return files
  }

  getCredentials () {
    return 'If this method gets called the backend class has NOT IMPLEMENTED the getCredentials method!'
  }

  getInstance (type) {
    const bList = this.getBackends()
    const bType = type + '-backend.js'

    // Check if it's a valid backend type.
    if (bList.indexOf(bType) === -1) {
      console.log(bType + ' is not a valid backend type.')
      return null
    }

    const backend = new (require(path.join(__appdir, 'lib', 'external-backends', 'backends', bType)))()
    return backend
  }
}

module.exports = ExternalBackends