summaryrefslogtreecommitdiffstats
path: root/server/api/backendtypes.js
diff options
context:
space:
mode:
authorJannik Schönartz2018-08-10 04:41:57 +0200
committerJannik Schönartz2018-08-10 04:41:57 +0200
commit17591fc7edf4104895b5842d9bf3b0e8eff98304 (patch)
tree619f44ce618f41771a617a8a5c289263c04346d7 /server/api/backendtypes.js
parent[permissions] fix bug with recursive-mode-switch (diff)
downloadbas-17591fc7edf4104895b5842d9bf3b0e8eff98304.tar.gz
bas-17591fc7edf4104895b5842d9bf3b0e8eff98304.tar.xz
bas-17591fc7edf4104895b5842d9bf3b0e8eff98304.zip
[server/router] Rework router
Reworked the router to match more design guidlines with the REST apis
Diffstat (limited to 'server/api/backendtypes.js')
-rw-r--r--server/api/backendtypes.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/server/api/backendtypes.js b/server/api/backendtypes.js
new file mode 100644
index 0000000..1bb1047
--- /dev/null
+++ b/server/api/backendtypes.js
@@ -0,0 +1,40 @@
+/* global __appdir */
+const path = require('path')
+const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends'))
+var db = require(path.join(__appdir, 'lib', 'sequelize'))
+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({ auth: false, status: 'TYPE_INVALID', error_message: 'The provided backend type is invalid.' })
+ }
+ res.status(200).send(instance.getCredentials())
+})
+
+module.exports.router = router