I've been doing a variant of the following:
// main.js
var IS_PARSE_SERVER;
try {
require('cloud/some-valid-module-in-hosted-parse');
IS_PARSE_SERVER = false;
} catch (e) {
IS_PARSE_SERVER = true;
}
but I realized adding a flag to the global Parse object should work the same way.
// app.js
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
// !!!
Parse.IS_PARSE_SERVER = true;
var api = new ParseServer({...});
var app = express();
app.use('/parse', api);
app.listen(1337);
// main.js
var IS_PARSE_SERVER = Parse.IS_PARSE_SERVER;
If you're doing this to run the same code on both parse.com and parse-server, the second approach seems better. I have been thinking recently about this middle-state where you have 2 api servers, 2 sets of cloud code, and how we can improve this.... but this is a decent solution in my book.
There are two methods that are not available on Parse Server:
Parse.User.current()Parse.Cloud.useMasterKey()You could check for the existence of these to determine if you're on Parse hosted Cloud Code. Of course this would only work as long as Parse Server does not support these methods.
For a more reliable method I'd recommend adding an environment variable like YUZEH_APP_PARSE_SERVER to the server you are running Parse Server on and checking that. That method will be guaranteed to never break due to changes in Parse Server, Parse.com, or the Parse JS SDK.
Most helpful comment
For a more reliable method I'd recommend adding an environment variable like
YUZEH_APP_PARSE_SERVERto the server you are running Parse Server on and checking that. That method will be guaranteed to never break due to changes in Parse Server, Parse.com, or the Parse JS SDK.