summaryrefslogtreecommitdiffstats
path: root/server/api/backendtypes.js
blob: ef371d8b6b3c654a0f900c7356e6180793a4acb5 (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
31
32
33
34
35
36
37
38
/* global __appdir */
const path = require('path')
const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends'))
var express = require('express')
var router = express.Router()

// GET requests.

/*
 * @return: Returns a list of all available backend types.
 */
router.get('/', (req, res) => {
  const backends = new ExternalBackends()
  var files = backends.getBackends()

  for (var i = 0; i < files.length; i++) {
    // Cut off -backends.js
    files[i] = files[i].slice(0, -11)
  }
  res.status(200).send(files)
})

/*
 * ?type=<BACKEND_TYPE>
 *
 * @return: Returns the credentials structure and fields of a backend type.
 */
router.get('/:type', (req, res) => {
  const backendType = req.params.type
  const b = new ExternalBackends()
  const instance = b.getInstance(backendType)
  if (instance === null) {
    res.status(500).send({ error: 'TYPE_INVALID', message: 'The provided backend type is invalid.' })
  }
  res.status(200).send(instance.getCredentials())
})

module.exports.router = router