Reputation: 33
I recently migrated parseserver to heroku, and everything seems to work perfectly except in my Cloud Code any Parse.Query does not seem to ever respond.
I can run custom cloud code, however anytime I need to run a Parse.Query the request times out.
here is my code:
Parse.Cloud.define("get_remaining_minutes", function(request, response) {
var config_name = "RWMTrialMinutes";
var minutesForPeriod = 120;
var isTrial = true;
var periodStartDate = new Date("01/01/2015");
var minutesUsed = 0;
console.log("userId=" + request.params.userId);
var userQuery = new Parse.Query(Parse.User);
userQuery.get({ useMasterKey: true }).then(request.params.userId, {
success: function(user) {
console.log("success");
response.success(100);
},
error: function(object, error) {
console.log("failed");
response.error(error);
}
});
});
I then call: curl -X POST -H "X-Parse-Application-Id: xxx" https://xxx.herokuapp.com/parse/functions/get_remaining_minutes?userId=dMbBrRGD1y
and get a timeout
2016-10-13T17:21:21.858269+00:00 heroku[router]: at=info method=POST path="/classes/_User" host=xxx.herokuapp.com request_id=xxx fwd="xxx" dyno=web.1 connect=0ms service=7ms status=404 bytes=225 2016-10-13T17:21:21.788404+00:00 app[web.1]: userId=dMbBrRGD1y 2016-10-13T17:21:51.759088+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/parse/functions/get_remaining_minutes?userId=dMbBrRGD1y" host=xxxx.herokuapp.com request_id=xxx fwd="xxx" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0
I've tried many different ways to query - tried .first, .get, .find, all seem to do the same thing - timeout. If i skip the .get call, the function works fine and I can response.success correctly. However I obviously need to make the query for my code to work.
I feel like i'm missing something basic, like a require or maybe a path is not set up correctly.
I will also mention I am running parse server and dashboard on the same Heroku application if you think that makes a difference as to why the cloud code is failing.
Any ideas?
Edit: adding my index.js code for starting parse-server and dashboard
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var ParseDashboard = require('parse-dashboard');
var path = require('path');
var allowInsecureHTTP = true;
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'xxx',
masterKey: process.env.MASTER_KEY || '',
serverURL: process.env.SERVER_URL || 'xxx.herokuapp.com/parse',
restAPIKey: 'xxx',
push:{
ios:{
pfx: 'Push.p12',
bundleId: 'xxx',
production: true
}
}
}, allowInsecureHTTP);
var dashboard = new ParseDashboard({
users: [{
user: 'admin',
pass: 'xxx'
}],
apps: [
{
serverURL: process.env.SERVER_URL + process.env.PARSE_MOUNT || 'https://xxx.herokuapp.com/',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '',
appName: process.env.APP_NAME || 'StoryTime',
iconName: 'Icon-60.png'
}
],
"iconsFolder": "icons"
}, allowInsecureHTTP);
var app = express();
app.use('/public', express.static(path.join(__dirname, '/public')));
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
//start the dashboard
app.use('/dashboard', dashboard);
app.get('/', function(req, res) {
res.status(200).send('I dream of being a website. Please star the parse- server repo on GitHub!');
});
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
Upvotes: 0
Views: 881
Reputation: 33
Turns out there were two problems - first the server was configured incorrectly. the SERVER_URL did not have /parse on it - and because the PARSE_MOUNT property was being used to route in express, I missed it. Second the syntax for useMasterKey needs to be like this for .get() - I had copied the code from somewhere online and it was not correct.
userQuery.get(request.params.userId, { useMasterKey:true, success: function(user)....
Upvotes: 1