2016-02-24 37 views
0

隨着Parse宣佈退休,我將Parse Server遷移到了Heroku上。有了我對Heroku的新手知識,我不知道他們是否具有與雲代碼類似的功能,但我知道幾個月前Parse Introduced a Heroku + Parse功能允許您在任何node.js環境中運行Cloud Code,特別是Heroku的。如何在Heroku上運行雲碼?

我的困境是,我已經將我的服務器從分析遷移到Heroku,然後才瞭解此功能:/,所以我無法從終端運行任何解析雲代碼,因爲現在沒有現有的服務器了。所以問題是,我如何在Heroku中模仿以下雲代碼&如何調整我的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) 
       } 
      } 
     } 
    } 

回答

0

我會先簽出example repo和讀取parse-serverdocumentation。解析服務器支持開箱即用的雲代碼,您只需在parse-server配置中指定哪個文件包含您的函數和觸發器即可。您在parse和heroku之間進行集成時發佈的鏈接與parse-server無關。