Parse-server: Parse.Query not working on Heroku (No Such App error)

Created on 24 Apr 2016  ·  21Comments  ·  Source: parse-community/parse-server

Environment Setup

  • Used the 'deploy to heroku' button from the migration guide

    Steps to reproduce

  • Upload this cloudcode function and call it

Parse.Cloud.define('debuggingFn', function(request, response) {
  var query = new Parse.Query("Speech");
  query.equalTo("speechId", "s_1456277936842");
  query.find({
    success: function(results) {
      console.log('SUCCESS', results)
      response.success("Success", results);
    },
    error: function(a, b) {
      // ERROR CAUGHT HERE: 'Heroku | No such app'
      console.log('ERROR', a, b)
      response.error("Error");
    }
  });
});

Logs/Trace

  • I expect to get a result, instead I get a (from the parse server logs)
ParseError {
2016-04-24T04:39:20.444057+00:00 app[web.1]:   code: 107,
2016-04-24T04:39:20.444079+00:00 app[web.1]:   message: 'Received an error with invalid JSON from Parse: _<bunch of html>_ <h1><strong>Heroku | No such app</strong></h1>\n            <div class=\'article\'>\n              <p>There is no app configured at that hostname.<br/>Perhaps the app owner has renamed it, or you mistyped the URL. _<bunch of html>_

Queries from the client website to my parse server work fine. Only the cloud code queries fail.

I believe I've followed every step from the migration guide, but googling doesn't return anyone else having this issue. So I guess I missed something?

This is the dependencies from my package.json file in the parse server project:

  "dependencies": {
    "express": "~4.11.x",
    "kerberos": "~0.0.x",
    "parse": "~1.8.0",
    "parse-server": "~2.2.7",
    "cors": "*"
  },

Most helpful comment

Make sure your parse-server is up to date and that you have serverUrl defined when starting it.

All 21 comments

I'm having a similar issue, but getting a different version of Parse Error 107. It looks like That-David-Guy is creating a custom function, whereas I'm just using afterSave.

The error:

ParseError {
code: 107,
message: 'Received an error with invalid JSON from Parse: Cannot POST /parse/classes/Class' }

Here is my function:

Parse.Cloud.afterSave("Class", function(request) {

    Parse.Cloud.useMasterKey();

    query = new Parse.Query("Class");
    query.find({

        success: function(results) {
            console.log("query success")
            console.log("Successfully retrieved " + results.length + " records.")
        },

        error: function(error) {
            console.log("query error")
            console.log(error)
        }

    })

});

@aaronbannin Your's might be because I don't think Parse.Cloud.useMasterKey() works anymore. You might need:

query.find({
        useMasterKey: true,
        success: function(results) {
            console.log("query success")
            console.log("Successfully retrieved " + results.length + " records.")
        },

Or something similar. I don't know, because I can't even get to that point :(

But let me know @aaronbannin if your query works!

Making the change has no impact.

Make sure your parse-server is up to date and that you have serverUrl defined when starting it.

@bohemima Thanks! The serverUrl config set in the heroku app had a typo in it. I fixed that and it's all working. Seems obvious now.

It all seems to be working now.

That does seem obvious now. Is there a better way to surface this? Perhaps run a test in the build process and output something like "Cloud code not configured properly, check your SERVER_URL config vars"?

@aaronbannin As in when the server starts up on heroku? Heroku was returning a result, being an error page, but not a 404 code. So I'm not sure how you would pick it up on the parse server end.

If you were interested in how I got the typo it was because I changed the heroku app name. The reason for that was as follows

  1. I thought a single parse server could hold multiple parse apps,
  2. I created my-app on heroku
  3. Realised you need a server for each parse app (I could be wrong about this, but this is my current thinking)
  4. I created my-app-prod on heroku
  5. Renamed my-app to my-app-dev on heroku
  6. Forgot to update the SERVER_URL for my-app-dev (this caused the error)

@That-David-Guy , my thinking is that the errors were not helpful in diagnosing the issue. In my case, Heroku set a default URL (it was something like "yourapp.com/parse").

@aaronbannin Heroku did set the default initially, which I forgot to/didn't realise to update when I changed the heroku app name. So if it is possible to do a check for that I think it would help.

I had the wrong mental modal about what parse server was doing. I didn't think Parse.query would actually make a url request to itself (when in cloud code), I assumed it would just call a method directly. Which is why when I got the error back about URLs I assumed it was a different error that was getting masked as a bad url.

Googling the heroku error suggested incorrectly that the Heroku Domain was wrong, which is different to parse's SERVER_URL config variable. This also added to my confusion.

Thanks again for your quick reply and helpful answers.

Can anyone shed some light on why when I attempt to implement the above code AS IS (only changing the "Class" to a class name that exists in my database)
` Parse.Cloud.afterSave("Class", function(request) {

Parse.Cloud.useMasterKey();

query = new Parse.Query("StudentNotes");
query.find({

    success: function(results) {
        console.log("query success")
        console.log("Successfully retrieved " + results.length + " records.")
    },

    error: function(error) {
        console.log("query error")
        console.log(error)
    }

})

});`

that I get this error:
2016-04-27 00:15:58.963 appName[72405:37534186] [Error]: Invalid function. (Code: 141, Version: 1.12.0)

Hi @Jerland2, I've closed this task as my original issue got resolved. You may have better luck opening a new issue or asking on stackoverflow.

For your issue I don't know what would be causing that. It doesn't seem like a very useful error. The only thing that stands out is that Parse.Cloud.useMasterKey(); is deprecated and you should use useMasterKey: true instead. Good luck!

I'm having a similar issue. I have a "hello world" cloud function which just returns:
response.success("Hello world!");
and that one seems to work.

However, my other function which is supposed to send push notifications to specific users is not working. It uses Parse.Query(User) type of thing. I wonder if that's the issue.

I was also using useMasterKey: true, but I took it out since the push function isn't working anyway.

Any help would be appreciated. Here is my code:

Parse.Cloud.define("pushToUser", function (request, response) {
    var userIdParam = request.params.userId;
    var message = request.params.message;
    var notifType = request.params.notifType;
    if (message != null && message !== "") {
        message = message.trim();
    } else {
        response.error("Must provide \"message\" in JSON data");
        return;
    }

    var userQuery = new Parse.Query(Parse.User);
    userQuery.equalTo('objectId', userIdParam);

    var pushQuery = new Parse.Query(Parse.Installation);

    // pushQuery.containedIn("deviceType", ["ios", "android"]); // errors if no iOS certificate
    pushQuery.exists("user"); // filter out installations without users
    pushQuery.include('user'); // expand the user pointer
    pushQuery.matchesQuery("user", userQuery);

    // Send push notification to query
    Parse.Push.send({
        where: pushQuery, // Set our installation query
        data: {
            alert: message,
            badge: "Increment",
            sound: "default",
            notificationText: message
            }
        }, {
        success: function () {
            // Push was successful
            var userInfoQuery = new Parse.Query("UserInfo");
            userInfoQuery.equalTo('userId', userIdParam);
            userInfoQuery.first({
                success: function(object) {
                    if (notifType == "message" || notifType == "bookup") {
                        object.increment("newChatCount", 1);
                    } else {
                        object.increment("newRequestCount", 1);
                    }
                    object.save();
                    response.success('true');
                },
                error: function(error) {
                    //just errored, still return
                    response.success('true');
                }
            });

        },
        error: function (error) {
            response.error(error);
        }
    });
});

@kanersan What do the logs say? Do you know which line is causing the error? Is the query closure failing or the push?

@aaronbannin
So I added something like this:

if (userQuery == null || pushQuery == null) {
    response.error("userQuery object or pushQuery object is nil");
    return;
}

just after defining those variables and that's not the response I got. So I'm assuming those are not the problem.

The response I get is:

[31merror: Error generating response. ParseError {
  code: 141,
  message: 
  ParseError {
  code: 107,
  message: 'Received an error with invalid JSON from Parse: Cannot POST /push\n' } } code=141, code=107, message=Received an error with invalid JSON from Parse: Cannot POST /push

@kanersan that feels like the problem is either in the data var in the Push.send closure or a Push config issue. Have you validated that push notifications work outside of this function?

@aaronbannin no I haven't, how can I do that?
Only thing i checked is when the app launches, the remote notification did register callback happens properly.

@kanersan I tested using the Parse Dashboard before sending via Cloud Code. You can send pushes from the dashboard, and it's pretty easy to get up and running.

https://github.com/ParsePlatform/parse-dashboard

Also, here is what I'm using for Push.send, note the useMasterKey argument:

Parse.Push.send({ where: pushQuery, data: { alert: pushText, sound: "default", pushType: pushType, pushArray: pushArray } }, {useMasterKey: true} );

@aaronbannin thanks for the help.

Btw, don't I need to configure this stuff explained here:
https://github.com/ParsePlatform/parse-cloud-express

Because I haven't done that yet... I thought cloud stuff would work out of box for Parse.

I don't remember touching that at all. Cloud code works out of the box, but
Pushes need some config.

https://github.com/ParsePlatform/PushTutorial/tree/master/iOS

I recall the only difference being that you can't upload the certificates
via the dashboard, so I just made a certificates/ dir in my server code and
set the target.

BTW...we've officially diverted far away from the thread. If you open a new
issue, feel free to tag me so I get notified.

On Wed, Dec 14, 2016 at 11:18 AM, Kaan Ersan notifications@github.com
wrote:

@aaronbannin https://github.com/aaronbannin thanks for the help.

Btw, don't I need to configure this stuff explained here:
https://github.com/ParsePlatform/parse-cloud-express

Because I haven't done that yet... I thought cloud stuff would work out of
box for Parse.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ParsePlatform/parse-server/issues/1613#issuecomment-267128639,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGoF8EcVoHpzl4EF4kgNVaSfmVydcEgrks5rIEEfgaJpZM4IOVx1
.

--
Thanks,

Aaron Bannin
[email protected]

I'm having the same issue, and chaning the SERVER_URL didn't change anything.

Was this page helpful?
0 / 5 - 0 ratings