made it possible to GET specific parts of the config
This commit is contained in:
parent
12e4a47855
commit
cc6b34dd46
|
@ -379,8 +379,29 @@ module.exports.create = function (deps, conf) {
|
|||
}
|
||||
|
||||
var config = { restful: {} };
|
||||
config.restful.readConfig = function (req, res) {
|
||||
res.send(deps.recase.snakeCopy(conf));
|
||||
config.restful.readConfig = function (req, res, next) {
|
||||
var part = conf;
|
||||
if (req.params.group) {
|
||||
part = part[req.params.group];
|
||||
}
|
||||
if (part && req.params.name) {
|
||||
part = part[req.params.name];
|
||||
}
|
||||
if (part && req.params.id) {
|
||||
part = part.find(function (mod) { return mod.id === req.params.id; });
|
||||
}
|
||||
if (part && req.params.name2) {
|
||||
part = part[req.params.name2];
|
||||
}
|
||||
if (part && req.params.id2) {
|
||||
part = part.find(function (mod) { return mod.id === req.params.id2; });
|
||||
}
|
||||
|
||||
if (part) {
|
||||
res.send(deps.recase.snakeCopy(part));
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
||||
config.restful.saveConfig = function (req, res) {
|
||||
console.log('config POST body', req.body);
|
||||
|
@ -400,7 +421,12 @@ module.exports.create = function (deps, conf) {
|
|||
app.use('/', isAuthorized, jsonParser);
|
||||
|
||||
app.use( '/config', makeCorsHandler());
|
||||
app.get( '/config', config.restful.readConfig);
|
||||
app.get( '/config', config.restful.readConfig);
|
||||
app.get( '/config/:group', config.restful.readConfig);
|
||||
app.get( '/config/:group/:name(modules|domains)', config.restful.readConfig);
|
||||
app.get( '/config/:group/:name(modules|domains)/:id', config.restful.readConfig);
|
||||
app.get( '/config/:group/:name(domains)/:id/:name2(modules)', config.restful.readConfig);
|
||||
app.get( '/config/:group/:name(domains)/:id/:name2(modules)/:id2', config.restful.readConfig);
|
||||
app.post( '/config', config.restful.saveConfig);
|
||||
return app;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue