Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add convenience access to Parse Server configuration in Cloud Code via Parse.Server #8244

Merged
merged 7 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
91 changes: 91 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,97 @@ describe('Cloud Code', () => {
});
});

it('can get config', () => {
const config = Parse.Server;
let currentConfig = Config.get('test');
expect(Object.keys(config)).toEqual(Object.keys(currentConfig));
expect(Object.keys(config).sort()).toEqual(
dblythy marked this conversation as resolved.
Show resolved Hide resolved
[
'_mount',
'allowClientClassCreation',
'allowCustomObjectId',
'analyticsController',
'appId',
'applicationId',
'auth',
'authDataManager',
'cacheController',
'cacheMaxSize',
'cacheTTL',
'clientKey',
'collectionPrefix',
'customPages',
'database',
'databaseAdapter',
'databaseURI',
'defaultLimit',
'directAccess',
'dotNetKey',
'emailVerifyTokenReuseIfValid',
'enableAnonymousUsers',
'enableExpressErrorHandler',
'enforcePrivateUsers',
'expireInactiveSessions',
'fileKey',
'fileUpload',
'filesAdapter',
'filesController',
'generateEmailVerifyTokenExpiresAt',
'generateSessionExpiresAt',
'graphQLPath',
'hasPushScheduledSupport',
'hasPushSupport',
'hooksController',
'host',
'idempotencyOptions',
'javascriptKey',
'jsonLogs',
'level',
'liveQueryController',
'logLevel',
'loggerController',
'logsFolder',
'masterKey',
'masterKeyIps',
'maxUploadSize',
'mountGraphQL',
'mountPath',
'mountPlayground',
'objectIdSize',
'pages',
'parseGraphQLController',
'playgroundPath',
'port',
'preserveFileName',
'preventLoginWithUnverifiedEmail',
'protectedFields',
'push',
'pushController',
'pushControllerQueue',
'pushWorker',
'readOnlyMasterKey',
'requestKeywordDenylist',
'restAPIKey',
'revokeSessionOnPasswordReset',
'scheduledPush',
'schemaCache',
'security',
'serverStartComplete',
'serverURL',
'sessionLength',
'silent',
'userController',
'verbose',
'verifyUserEmails',
'webhookKey',
].sort()
);
config.silent = false;
Parse.Server = config;
currentConfig = Config.get('test');
expect(currentConfig.silent).toBeFalse();
});

it('show warning on duplicate cloud functions', done => {
const logger = require('../lib/logger').logger;
spyOn(logger, 'warn').and.callFake(() => {});
Expand Down
10 changes: 10 additions & 0 deletions src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ class ParseServer {

function addParseCloud() {
const ParseCloud = require('./cloud-code/Parse.Cloud');
Object.defineProperty(Parse, 'Server', {
get() {
return Config.get(Parse.applicationId);
},
set(newVal) {
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
newVal.appId = Parse.applicationId;
Config.put(newVal);
},
configurable: true,
});
Object.assign(Parse.Cloud, ParseCloud);
global.Parse = Parse;
}
Expand Down