How to move cloud code from parse.com to heroku

2020-07-22 18:55发布

问题:

I have moved parse sever from parse.com to heroku. Everything is working fine except cloud code('cloud/main.js' file).

I have replaced "main.js" of parse.com with "main.js" of parse server code and deployed on heroku, but it is not working. Getting following error when I make request from my mobile app

{"code":1,"message":"Internal server error."} (Code: 1, Version: x.xx.x)

Any idea?

Note: I've followed following link for migrating parse server

https://learnappmaking.com/how-to-migrate-parse-app-parse-server-heroku-mongolab/

回答1:

Migrating cloud code can range in difficulty depending on how involved that code is. Here's a workflow for validating your code:

1) Check that you can build your Heroku app locally with the right Node version.

2) Comment out all of your cloud code. You want to start introducing your code in parts and make sure it compiles with each re-introduced function.

3) Install the node modules for each service that you use. If you use stripe/mailgun or any other package, add them in your package.json file and run npm install. Then include them in your main.js file with the require('packageName').

4) The cloud server uses Express.js version 4.2 and a Parse.com runs Express version 2.0 or 3.0 but not 4.0. If you use any middlewear then you need to change it to the proper Express 4.0 syntax/methodology.

5) There is no support for cloud jobs so rename all your *.job functions to *.define and comment properly so you can come back to them later. If you did not use cloud jobs then don't worry.

6) If you did use cloud jobs, now you need to setup a heroku worker/scheduler to run those old *.job (now *.define) calls at the proper time intervals you had.