(To be clear, Im asking this question so as to provide the answer I found in an effort to help others that have been similarly affected by the Parse closure)
Parse.com recently anounced that they are closing shop January 2017 but thankfully they have made their Parse Server software open source so we can all host our own Parse server instances.
I have looked into the various options available for hosting Parse Server and have decided to host mine on Heroku
I loved Parse because it was so easy to use and I have no real experience with setting up a backend. I have tried to follow several guides online but found them all a bit hard to understand with vague steps or steps that take you down a rabbit hole on another site installing a bunch of tools and it all gets a bit confusing.
How can I host Parse Server on heroku, set it up to accept cross domain requests from my application, create a MongoDB database, and migrate all of my data from Parse to the new database?
https://www.parse.com/apps/<APP_NAME>/edit#keys
where <APP_NAME>
is the name of your app. If you're creating a new app you can generate random keys here. You can add new keys for any sdks you plan to use, I'm adding one for the javascript sdk here.Install the Heroku Toolbelt which is a command line interface tool for managing your Heroku apps.
Open a terminal prompt and enter $ heroku login
, enter your Heroku email and password
Enter $ heroku git:clone -a <MY_APP_NAME>
(where <MY_APP_NAME>
is the name of your heroku app) to make a local copy of your server code repo, you can also use the git url from we saw earlier. When you clone the repo you will see the message "warning: You appear to have cloned an empty repository.". The app folder will be created but it will only contain the standard git files and no parse server. To fix this. Go to the official parse-server-example git repo, download the zip file of the repo. Extract the folder, drag all of the files and folders from the parse-server-example-master folder into your app folder.
Back in the terminal, enter $ cd <MY_APP_NAME>
to move into the repo
package.json
and add "cors": "*"
to the dependencies
like this:.
"dependencies": { "express": "~4.2.x", "kerberos": "~0.0.x", "parse": "~1.6.12", "parse-server": "~2.0", // <= don't forget this comma "cors": "*" // add this line }
Make sure to remove the above comments in your actual code as it wont be valid JSON
index.js
and make these changes:.
var express = require('express'); // find this line in the file var cors = require('cors') // add this line below it //.... //var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI // old name, you may need to change this for new deployments var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI // changed to MONGODB_URI in Heroku! //.... var app = express(); // find this line in the file app.use(cors()); // add this line below it //Add declarations for any keys you plan to use as shown below var api = new ParseServer({ databaseURI: databaseUri || 'mongodb://localhost:27017/dev', cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', appId: process.env.APP_ID || 'myAppId', masterKey: process.env.MASTER_KEY || '', serverURL: process.env.SERVER_URL || 'http://localhost:1337', javascriptKey: process.env.JAVASCRIPT_KEY || '', //** add this line no need to set values, they will be overwritten by heroku config vars restAPIKey: process.env.REST_API_KEY || '', //** add this line dotNetKey: process.env.DOT_NET_KEY || '', //** add this line clientKey: process.env.CLIENT_KEY || '', //** add this line });
.
$ git add . $ git commit -am "make it better" $ git push heroku master
<MY_APP_ID>
,<MY_JS_KEY>
,<MY_HEROKU_APP_NAME>
in the fiddle to the appropriate values for your app then click "Run".
Parse.initialize('<MY_APP_ID>', '<MY_JS_KEY>'); Parse.serverURL = 'https://<MY_HEROKU_APP_NAME>.herokuapp.com/Parse'
If, you use the jsfiddle tool with multiple parse server instances, you might get the error "invalid session token". If this happens, open the dev console, and delete all of the "parse" keys from local storage, after that, it should work:
You should do this at least once with a test app before migrating a production app. Also, it seems that legacy files
from your old app may not yet transfer, see this GitHub Issue
https://dashboard.heroku.com/apps/<MY_HEROKU_APP_NAME>/resources
, click "MongoLab" next to it's icon, then, on the next page, click "Delete all collections"https://dashboard.parse.com/apps/<APP_NAME>/settings/general
where <APP_NAME>
is the name of your parse appMONGOLAB_URI
that we made note of earlierIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With