Skip to content

Parse.Query not working on Heroku (No Such App error) #1613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
That-David-Guy opened this issue Apr 24, 2016 · 21 comments
Closed

Parse.Query not working on Heroku (No Such App error) #1613

That-David-Guy opened this issue Apr 24, 2016 · 21 comments

Comments

@That-David-Guy
Copy link

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": "*"
  },
@aaronbannin
Copy link

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)
        }

    })

});

@That-David-Guy
Copy link
Author

That-David-Guy commented Apr 24, 2016

@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 :(

@That-David-Guy
Copy link
Author

But let me know @aaronbannin if your query works!

@aaronbannin
Copy link

Making the change has no impact.

@bohemima
Copy link
Contributor

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

@That-David-Guy
Copy link
Author

@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.

@aaronbannin
Copy link

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"?

@That-David-Guy
Copy link
Author

@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)

@aaronbannin
Copy link

@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").

@That-David-Guy
Copy link
Author

@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.

@Jerland2
Copy link

Jerland2 commented Apr 27, 2016

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)

@That-David-Guy
Copy link
Author

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!

@kaanselhep
Copy link

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);
        }
    });
});

@aaronbannin
Copy link

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

@kaanselhep
Copy link

kaanselhep commented Dec 14, 2016

@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�[39m: 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

@aaronbannin
Copy link

@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?

@kaanselhep
Copy link

@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.

@aaronbannin
Copy link

@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} );

@kaanselhep
Copy link

@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.

@aaronbannin
Copy link

aaronbannin commented Dec 14, 2016 via email

@MatheussAlves
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants