解析Javascript和Cloud Code

时间:2017-09-17 20:47:05

标签: javascript parse-platform back4app

我正在尝试设置一个简单的测试网页来执行一些从Parse发送推送通知的云代码。我用back4app.com。以下是我到目前为止的情况:

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>

但是当我在文本框中添加一些文本时,我会收到这些错误:

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

出了什么问题?在Parse Developers JS指南中,它说:

  

要使用Javascript初始化您自己的Parse-Server,您应该这样做   用这个

替换当前的初始化代码
Parse.initialize("YOUR_APP_ID"); 
Parse.serverURL = 'http://YOUR_PARSE_SERVER:1337/parse'

我使用了我在iOS应用中使用的back4app网址。如此困惑

1 个答案:

答案 0 :(得分:0)

请确保您遵循以下结构:

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