• 6 min read

Azure welcomes Parse developers

If you have been using Parse hosting as the backend that supports your mobile apps, this may be the perfect time to try out Azure App Service.

UPDATE:  Microsoft has released a Marketplace template to simplify the process of implementing Parse on Azure.  For more details, please see Announcing the publication of Parse Server with Azure Managed Services.

If you have been using Parse hosting as the backend that supports your mobile apps, this may be the perfect time to try out Azure App Service. Due to recent occurrences, the folks at Parse have provided a way to migrate an existing backend hosted by Parse to another host. When searching for a new host, we hope that you try Azure.

An easy migration path

As the Parse migration guide suggests, you can migrate the Parse-hosted backend used by your app to another host, with the Parse server API mounted on an Express app. Azure App Service makes a great alternative for hosting your Parse server implementation. After all, the Node.js backend for Mobile Apps in Azure App Service is also an Express app. To make things even easier for you to get started, the Azure App Service team has created a streamlined provisioning process that makes it very easy to get your Parse server running in App Service.

Before you start, you should probably read through the Parse migration guide so that you can understand what is and isn’t supported by the new Parse server. One major mobile app feature missing from the Parse server is push notifications, but using Azure Notification Hubs is a great alternative there too.

When the migration is complete, you can continue to use the Parse client SDKs in your apps accessing your existing data (of course the clients will also need to be updated to use new versions of the SDKs and to point at the new service location).

Before you begin

Before you jump into the process of creating a new Parse server running on Azure, you will need to do the following:

Create your Azure subscription

If you don’t already have an Azure subscription, you will need to sign up for one. A free trial subscription is available.

Set up a MongoDB

One of the current requirements of Parse server is using MongoDB (Parse provides guidance for MongoDB requirements). Parse is also promising a migration tool to enable you to move your Parse-hosted data out to MongoDB. If this is your experience with MongoDB, Parse recommends starting out with the MongoLab service, a fully-managed cloud database service that you can also sign-up for through Azure Marketplace. However you choose to host your MongoDB, you’ll need the connection info to run the Parse server.

In the future, you should also consider using Azure DocumentDB, a managed NoSQL document database-as-a-service. In subsequent posts, we will share instructions on how to migrate your data to DocumentDB and use DocumentDB with your Parse server.

Get a GitHub account

The migration path to Azure demonstrated in this post requires you to have a GitHub account. It is also helpful for you to know how to clone a Git repo and to commit and push changes to the repo.

Create a new backend in App Service

The first step is to create a new backend in App Service to host your Parse server. In the Azure portal, click + New > Web + Mobile > Web app, enter a unique name for your backend, then click Create.

Create new app service in Azure portal

This creates the new backend service that will host your Parse server. Before you do this, you may want to create a different App Service plan as this affects the pricing of your service. You can always change your App Service plan later. For more information, see Azure App Service plans in-depth overview.

After the initial deployment is complete, you will see the blade for your new backend.

New web app in Azure portal

App service provides various ways to deploy your app. Next, you will set up a deployment from a Parse server repo.

Clone the Parse server repo and deploy to Azure

To make it easy to publish a Parse server on Azure, the App Service team has forked the Parse server example repo to create a customized Parse server that runs correctly in App Service. In GitHub, fork the Azure Parse server sample repo into your account.

Fork the Parse server example repo

You will use this fork as the deployment source for your backend. Back in the Settings blade for your newly created backend, scroll down and click Continuous deployment > Choose source > GitHub, then click Authorization > Authorize, grant access to the Azure management portal in the GitHub page that is displayed (you will probably also need to provide your GitHub password), then click OK.

Set up GitHub continous deployment

Now that the portal is connected to your GitHub account, choose your fork of the parse-server-example as the project, choose the master branch, then click OK.

Set deployment credentials

At this point, the deployment is set up and the Parse server code is pulled from the GitHub project and published to Azure. If for some reason the deployment isn’t triggered, you can also manually trigger a sync by clicking on the Sync button on the Deployments blade.

Configure the backend

The Parse server requires several pieces of information, which are best provided as environment variables, known as app settings in App Service. This includes the MongoDB connection info and the app ID and master key values. Using app settings provides better security since this important information isn’t left in your code where it could be left unsecured or published to a public repo.  To create new app settings, in the Settings blade, click Application Settings, scroll down to the App settings section and create new key/value pairs for the following settings, then click Save:

Key Value

DATABASE_URI

The MongoDB connection string

APP_ID

Your Parse app Id

MASTER_KEY

Your Parse master key

Parse application settings in the portal

At this point, you should be able to access your new Parse server using a REST client. If your Parse server requires other hard-coded values, such as a Facebook App ID, you should also add these to app settings.

Try out the Hello World

The Parse server example project has a “hello world” function named hello, which you can call using cURL as follows:

$ curl -X POST 
>   -H "X-Parse-Application-Id: dsXH3syuEuuIZvXi1niEtX49LLilneJK5oIBcLM3" 
>   -H "Content-Type: application/json" 
>   -d '{}' 
>   

This should be a familiar call to most Parse developers. But this time the response from the service is decidedly different:

{"result":"Hello from Azure."}

Now that you have verified that the Parse server is running correctly on Azure, it’s time to add your cloud code to the deployment.

Add your Parse cloud code

Since you now have continuous deployment configured using your fork of the Parse server sample repo, it’s easiest to use this GitHub repo to add your Parse cloud code to the deployment.

To add your cloud code to the deployment, clone your fork of the Parse server sample repo on your local computer using a Git client or command-line tool, like GitBash.

From your local Parse installation, copy the /Cloud and /Public subfolders to your new local clone, then add, commit and push the changes back up to your origin in GitHub. When you push to GitHub, you will see that deployment is again triggered. After the deployment completes successfully, your cloud code is ready to use.

Please note that this requires you to add your cloud code to a public GitHub repo. To keep your code private, you'll need to duplicate this repository into a private one, or you can first switch to use another deployment method.

Update the Parse SDK in client apps

The new Parse server and new hosting environment requires updates in the Parse SDKs used by your client apps. Make sure you follow the instructions in Using Parse SDKs with Parse Server.

What about push notifications?

When you read the Parse server migration guide closely, you will see this:

Parse Server does not implement any push notification functionality. We recommend migrating to a different push provider.

Don’t panic. Azure has a highly scalable service designed specifically to send push notifications to mobile apps, Azure Notification Hubs. As you did with push in Parse, Notification Hubs stores authentication information for each Push Notification Service (PNS), APNS, GCM, WNS, even Kindle, Chrome, and Baidu. The Notification Hubs Node.js library lets you easily send push notifications from your cloud code, or from nearly any other backend service. We will provide guidance in the near future on how to use Notification Hubs to send push notifications from a Parse server.

Conclusion

Once you have gotten used to the Azure App Service hosting environment for your Parse server, consider investigating other Azure services that provide some of the features of Parse hosting that are missing from Parse server, like analytics, scheduled jobs, and integration with third-party services like Twillio and SendGrid. App Service also offers more built-in authentication options that Parse server.

We hope that you have a great experience in trying out Azure for hosting your Parse server. Best of luck on your migration from Parse hosting to a new backend home for your app.

Cheers,

Glenn Gailey