Merge pull request #283 from theill/master
Implementing GET /config and POST /config support
This commit is contained in:
@@ -48,6 +48,10 @@ ExportAdapter.prototype.collection = function(className) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME,
|
||||
'invalid className: ' + className);
|
||||
}
|
||||
return this.rawCollection(className);
|
||||
};
|
||||
|
||||
ExportAdapter.prototype.rawCollection = function(className) {
|
||||
return this.connect().then(() => {
|
||||
return this.db.collection(this.collectionPrefix + className);
|
||||
});
|
||||
|
||||
46
src/global_config.js
Normal file
46
src/global_config.js
Normal file
@@ -0,0 +1,46 @@
|
||||
// global_config.js
|
||||
|
||||
var Parse = require('parse/node').Parse,
|
||||
PromiseRouter = require('./PromiseRouter');
|
||||
|
||||
var router = new PromiseRouter();
|
||||
|
||||
function getGlobalConfig(req) {
|
||||
return req.config.database.rawCollection('_GlobalConfig')
|
||||
.then(coll => coll.findOne({'_id': 1}))
|
||||
.then(globalConfig => ({response: { params: globalConfig.params }}))
|
||||
.catch(() => ({
|
||||
status: 404,
|
||||
response: {
|
||||
code: Parse.Error.INVALID_KEY_NAME,
|
||||
error: 'config does not exist',
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
function updateGlobalConfig(req) {
|
||||
if (!req.auth.isMaster) {
|
||||
return Promise.resolve({
|
||||
status: 401,
|
||||
response: {error: 'unauthorized'},
|
||||
});
|
||||
}
|
||||
|
||||
return req.config.database.rawCollection('_GlobalConfig')
|
||||
.then(coll => coll.findOneAndUpdate({ _id: 1 }, { $set: req.body }))
|
||||
.then(response => {
|
||||
return { response: { result: true } }
|
||||
})
|
||||
.catch(() => ({
|
||||
status: 404,
|
||||
response: {
|
||||
code: Parse.Error.INVALID_KEY_NAME,
|
||||
error: 'config cannot be updated',
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
router.route('GET', '/config', getGlobalConfig);
|
||||
router.route('PUT', '/config', updateGlobalConfig);
|
||||
|
||||
module.exports = router;
|
||||
@@ -121,6 +121,9 @@ function ParseServer(args) {
|
||||
router.merge(require('./installations'));
|
||||
router.merge(require('./functions'));
|
||||
router.merge(require('./schemas'));
|
||||
if (process.env.PARSE_EXPERIMENTAL_CONFIG_ENABLED || process.env.TESTING) {
|
||||
router.merge(require('./global_config'));
|
||||
}
|
||||
|
||||
batch.mountOnto(router);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user