summaryrefslogtreecommitdiffstats
path: root/server/router.js
diff options
context:
space:
mode:
authorUdo Walter2018-07-30 01:31:08 +0200
committerUdo Walter2018-07-30 01:31:08 +0200
commitf6cadb25e42e6568098f2962fa9b302cfbf074c5 (patch)
tree4dd205c43603b22d00b2b51a162922643014e436 /server/router.js
parent[store/global] simplified settings loading (diff)
downloadbas-f6cadb25e42e6568098f2962fa9b302cfbf074c5.tar.gz
bas-f6cadb25e42e6568098f2962fa9b302cfbf074c5.tar.xz
bas-f6cadb25e42e6568098f2962fa9b302cfbf074c5.zip
[server/router] changed api routing from query keyword to url parameter for group and client api (todo: the rest)
Diffstat (limited to 'server/router.js')
-rw-r--r--server/router.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/server/router.js b/server/router.js
index bde35a8..6c0e4cd 100644
--- a/server/router.js
+++ b/server/router.js
@@ -2,6 +2,16 @@ var express = require('express')
var router = express.Router()
var path = require('path')
+function mapActions (api, method) {
+ return function (req, res) {
+ if (method in api && req.params.action in api[method]) {
+ api[method][req.params.action](req, res)
+ } else {
+ res.status(501).end()
+ }
+ }
+}
+
// Authentication routes
var auth = require(path.join(__dirname, 'lib', 'authentication'))
router.get('/auth', auth.auth)
@@ -16,13 +26,13 @@ router.get('/user/info', auth.verifyToken, user.info)
// Groups API
var groups = require(path.join(__dirname, 'api', 'groups'))
-router.get('/groups', groups.get)
-router.post('/groups', groups.post)
+router.get('/groups/:action', mapActions(groups, 'get'))
+router.post('/groups/:action', mapActions(groups, 'post'))
// Clients API
var clients = require(path.join(__dirname, 'api', 'clients'))
-router.get('/clients', clients.get)
-router.post('/clients', clients.post)
+router.get('/clients/:action', mapActions(clients, 'get'))
+router.post('/clients/:action', mapActions(clients, 'post'))
// Permissions API
var permissions = require(path.join(__dirname, 'api', 'permissions'))