Parse Javascript and Cloud Code

445 views Asked by At

I am trying to set up a simple test webpage to execute some cloud code that sends a push notification from Parse. I use back4app.com. Here is what I have so far:

JS:

Parse.initialize('APP_ID');
Parse.serverUrl = 'https://parseapi.back4app.com/';

function sendPushNotification() {

    let messageBox = document.getElementById('messageBox');
    let messageToPush = messageBox.value;

    Parse.Cloud.run("sendPushNotification", { message: messageToPush }).then(function(result) {
        console.log("result: " + JSON.stringify(result));
    }, function(error) {
        console.log("Error: " + JSON.stringify(error));
    });
}

HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>title</title>
        <script src="https://unpkg.com/parse/dist/parse.min.js"></script>
        <script src="main.js"></script>
    </head>
    <body>
            Message to Push:<br>
            <input id="messageBox" type="text" /><br>
            <input type="button" value="Push" onclick="sendPushNotification()" />
    </body>
</html>

But when I add some text to the text box, I get these errors:

[Error] Failed to load resource: The certificate for this server is invalid. You might be connecting to a server that is pretending to be “api.parse.com” which could put your confidential information at risk. (sendPushNotification, line 0)

What is going wrong? In the Parse Developers JS Guide, it says:

To initialize your own Parse-Server with Javascript, you should replace your current initialization code with this

Parse.initialize("YOUR_APP_ID"); 
Parse.serverURL = 'http://YOUR_PARSE_SERVER:1337/parse'

I used the back4app url that I use in my iOS app. So confused

1

There are 1 answers

1
Charles On

Please make sure you're following this structure below:

Parse.initialize("YOUR_APP_ID", "YOUR_JAVASCRIPT_KEY");
Parse.serverURL = 'https://parseapi.back4app.com'