【问题标题】:How do I run a Cloud Code on Heroku?如何在 Heroku 上运行云代码?
【发布时间】:2016-02-24 10:33:49
【问题描述】:

随着 Parse 宣布退役,我已将 Parse 服务器迁移到 Heroku。凭借我对 Heroku 的新手知识,我不知道它们是否具有与 Cloud Code 类似的功能,但我知道几个月前 Parse Introduced a Heroku + Parse 允许您在任何 node.js 环境中运行 Cloud Code 的功能,尤其是 Heroku。

我的困境是,在了解此功能之前,我已经将我的服务器从 parse 迁移到 Heroku:/,所以我无法从我的终端运行任何解析云代码,因为那里已经没有现有的服务器了。所以问题是,我如何在 Heroku 中模拟以下 Cloud Code 以及如何调整我的 swift?

云代码:

// Use Parse.Cloud.define to define as many cloud functions as you want.
// For example:

Parse.Cloud.define("isLoginRedundant", function(request, response) {
    Parse.Cloud.useMasterKey();
    var sessionQuery = new Parse.Query(Parse.Session);
    sessionQuery.equalTo("user", request.user);
    sessionQuery.find().then(function(sessions) {
        response.success( { isRedundant: sessions.length>1 } );
    }, function(error) {
        response.error(error);
    });
});

这是我在 xcode 中的快速返回:

    PFUser.logInWithUsernameInBackground(userName!, password: passWord!) {
        (user, error) -> Void in
        if (user != nil) {
            // don't do the segue until we know it's unique login
            // pass no params to the cloud in swift (not sure if [] is the way to say that)
            PFCloud.callFunctionInBackground("isLoginRedundant", withParameters: [:]) {
                (response: AnyObject?, error: NSError?) -> Void in
                let dictionary = response as! [String:Bool]
                var isRedundant : Bool
                isRedundant = dictionary["isRedundant"]!
                if (isRedundant) {
                    // I think you can adequately undo everything about the login by logging out
                    PFUser.logOutInBackgroundWithBlock() { (error: NSError?) -> Void in
                        // update the UI to say, login rejected because you're logged in elsewhere
                        // maybe do a segue here? 
                        let redundantSession: String = "you are already logged in on another device"
                        self.failedMessage(redundantSession)

                        self.activityIND.stopAnimating()

                        self.loginSecond.userInteractionEnabled = true
                    }
                } else {
                    // good login and non-redundant, do the segue 
                    self.performSegueWithIdentifier("loginSuccess", sender: self) 
                } 
            } 
        } else {
            // login failed for typical reasons, update the UI 
            dispatch_async(dispatch_get_main_queue()) {

                self.activityIND.stopAnimating()

                self.loginSecond.userInteractionEnabled = true

                if let message = error?.userInfo["error"] as? String
                    where message == "invalid login parameters" {
                        let localizedMessage = NSLocalizedString(message, comment: "Something isn't right, check the username and password fields and try again")
                        print(localizedMessage)
                        self.failedMessage(localizedMessage)
                }else if let secondMessage = error?.userInfo["error"] as? String
                    where secondMessage == "The Internet connection appears to be offline." {
                    self.failedMessage(secondMessage)
                }
            }
        }
    }

【问题讨论】:

    标签: ios swift heroku parse-cloud-code parse-server


    【解决方案1】:

    我会先查看example repo 并阅读parse-server documentation。解析服务器支持开箱即用的云代码,您只需在解析服务器配置中指定哪个文件包含您的函数和触发器。您发布的 parse 和 heroku 集成的链接与 parse-server 无关。

    【讨论】:

      猜你喜欢
      • 2018-08-29
      • 1970-01-01
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      • 2021-08-19
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      相关资源
      最近更新 更多