Skip to content
Open
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
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "9.6.0-alpha.33",
"description": "An express module providing a Parse-compatible API server",
"main": "lib/index.js",
"exports": {
".": "./lib/index.js",
"./cloud": "./lib/cloud.js"
},
"repository": {
"type": "git",
"url": "https://github.com/parse-community/parse-server"
Expand Down
35 changes: 9 additions & 26 deletions src/ParseServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var batch = require('./batch'),
express = require('express'),
middlewares = require('./middlewares'),
Parse = require('parse/node').Parse,
{ parse } = require('graphql'),
path = require('path'),
fs = require('fs');
Expand Down Expand Up @@ -46,9 +45,7 @@ import Deprecator from './Deprecator/Deprecator';
import { DefinedSchemas } from './SchemaMigrations/DefinedSchemas';
import OptionsDefinitions from './Options/Definitions';
import { resolvingPromise, Connections } from './TestUtils';

// Mutate the Parse object to add the Cloud Code handlers
addParseCloud();
import { LegacyCloud } from './cloud-code/LegacyCloud';

// Track connections to destroy them on shutdown
const connections = new Connections();
Expand All @@ -61,6 +58,7 @@ class ParseServer {
server: any;
expressApp: any;
liveQueryServer: any;
private legacyCloud: LegacyCloud;
/**
* @constructor
* @param {ParseServerOptions} options the parse server initialization options
Expand Down Expand Up @@ -128,9 +126,9 @@ class ParseServer {
javascriptKey,
serverURL = requiredParameter('You must provide a serverURL!'),
} = options;
// Initialize the node client SDK automatically
Parse.initialize(appId, javascriptKey || 'unused', masterKey);
Parse.serverURL = serverURL;
// Initialize the registrar and legacy cloud SDK
this.legacyCloud = new LegacyCloud();
this.legacyCloud.initialize({ appId, masterKey, javascriptKey, serverURL });
Config.validateOptions(options);
const allControllers = controllers.getControllers(options);

Expand Down Expand Up @@ -163,6 +161,7 @@ class ParseServer {
schema,
liveQueryController,
} = this.config;
const Parse = this.legacyCloud.Parse;
try {
await databaseController.performInitialization();
} catch (e) {
Expand All @@ -185,7 +184,7 @@ class ParseServer {
startupPromises.push(liveQueryController.connect());
await Promise.all(startupPromises);
if (cloud) {
addParseCloud();
this.legacyCloud.bindToParseCloud();
if (typeof cloud === 'function') {
await Promise.resolve(cloud(Parse));
} else if (typeof cloud === 'string') {
Expand Down Expand Up @@ -373,6 +372,7 @@ class ParseServer {
});
}
if (process.env.PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS === '1' || directAccess) {
const Parse = require('parse/node').Parse;
Parse.CoreManager.setRESTController(ParseServerRESTController(appId, appRouter));
}
return api;
Expand Down Expand Up @@ -535,6 +535,7 @@ class ParseServer {
}

static async verifyServerUrl() {
const Parse = require('parse/node').Parse;
// perform a health check on the serverURL value
if (Parse.serverURL) {
const isValidHttpUrl = string => {
Expand Down Expand Up @@ -577,24 +578,6 @@ class ParseServer {
}
}

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

function injectDefaults(options: ParseServerOptions) {
Object.keys(defaults).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(options, key)) {
Expand Down
Loading