I'm currently using Node.js + Parse Server for an app, using most of the Parse SDK from the client, with still many changes and refactors to do to the app to be done. One of the problems this app has, is that some of the logic should be located at the Cloud Code instead of built in the client.
Currently I only have a very little bunch of functions built in the Parse Cloud Code, and they are a big mess, because:
Resuming: I think that the best solution is to make a Node.js instance to manage the Cloud Code. It would have the master key and total access to the Parse server, so it can work pretty much like a client does, but just not exposing the logic to a hypothetical attacker.
How would you do this? Which considerations should I have into account?
Thank you!
One thing you should understand is: Parse Server is a Node.js server. It just handles many things such as authentication, session management, etc, out-of-the-box.
To address your specific concerns:
'use strict';
to the top of my files to make it work. Parse does support promises. Not only does it have a Parse-native promise library (here), you can also add any Promise library as an NPM module. I typically add Bluebird to my package.json so that I can use some of the cool collection methods (map, each, etc).Problem Two: I'll admit that it is kinda annoying to have all your functions in one file, but I've come up with a solution that makes it a little easier: I just pass the (request, response)
to a function in a different module:
const userTrigger = require('./triggers/userTrigger.js');
Parse.Cloud.beforeSave('_User', (request, response) => {
userTrigger.beforeSave(request, response);
});
// *notice ES6 syntax above
Problem Three: I'm not sure what your problem is here. Are you hosting your MongoDB instance on the same machine as Parse Server? Then, yeah I think you should host it on a separate machine. But I think your approach of having a "client" that hosts your backend logic is overkill. Just to reiterate: Parse Server is a backend server... that's where your backend logic should reside.
Let me know if you're still having trouble. Even if you don't use cloud-code, you can still have traditional API endpoints that are hosted on the same machine as your Parse Server. Take a look in index.js within Parse Server, I've written many functions at this level so that I can bypass the Parse Server component of the app.