Skip to content

feat: Allow updating Parse Server options dynamically #8449

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 6 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,16 @@ describe('Cloud Code', () => {
});
});

it('can get config', () => {
const config = Parse.Server;
it('can get and set config', () => {
let currentConfig = Config.get('test');
expect(Object.keys(config)).toEqual(Object.keys(currentConfig));
config.silent = false;
Parse.Server = config;
expect(Object.keys(Parse.Server)).toEqual(Object.keys(currentConfig));
Parse.Server.set('silent', ['abc']);
currentConfig = Config.get('test');
expect(currentConfig.silent).toBeFalse();
expect(currentConfig.silent).toEqual(['abc']);
});

it('can throw on invalid config', () => {
expect(() => Parse.Server.set('foo', true)).toThrow('foo is not a valid Parse Server option');
});

it('show warning on duplicate cloud functions', done => {
Expand Down
9 changes: 9 additions & 0 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,15 @@ export class Config {
? this.pages.pagesEndpoint
: 'apps';
}

set(key, value) {
if (!ParseServerOptions[key]) {
throw `${key} is not a valid Parse Server option`;
}
this[key] = value;
Config.put(this);
return this;
}
}

export default Config;
Expand Down
17 changes: 7 additions & 10 deletions src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,13 @@ class ParseServer {

function addParseCloud() {
const ParseCloud = require('./cloud-code/Parse.Cloud');
Object.defineProperty(Parse, 'Server', {
get() {
return Config.get(Parse.applicationId);
},
set(newVal) {
newVal.appId = Parse.applicationId;
Config.put(newVal);
},
configurable: true,
});
if (!Parse.Server) {
Object.defineProperty(Parse, 'Server', {
get() {
return Config.get(Parse.applicationId);
},
});
}
Object.assign(Parse.Cloud, ParseCloud);
global.Parse = Parse;
}
Expand Down