I cannot access to response object in a cloud code function?

I’ve searched a lot around and coudn’t find a way to access the response object of a cloud function (I’m using parse-server version 3.10.0). I’m missing something?

This is a basic need for every express developer. How can I add response headers, change the response statusCode, sending different Content-Type, pipe stream data to response etc. etc?

Please help. Thanks

That’s not the purpose of cloud code functions. If you want to handle the express.js request/response by yourself for more customized usage, you can just mount custom routes or middleware to the app. Something like:

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();

var api = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/dev', // Connection string for your MongoDB database
  cloud: '/home/myApp/cloud/main.js', // Absolute path to your Cloud Code
  appId: 'myAppId',
  masterKey: 'myMasterKey', // Keep this key secret!
  fileKey: 'optionalFileKey',
  serverURL: 'http://localhost:1337/parse' // Don't forget to change to https if needed
});

// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

app.use('/your-custom-path', yourCustomMidleware);

app.listen(1337, function() {
  console.log('parse-server-example running on port 1337.');
});

@davimacedo Would it be possible to do a combination? I’d like to keep all the logic I have for logging in, while still being able to set a cookie on the response from the server. Do you have any recommendations?

Yes. You can create additional custom express.js middleware on top of the existing api that parse server automatically generates.

1 Like