Getting Started with LoopBack on Cloud Foundry
Most mobile developers want to focus on the front-end of their apps and not get caught up in having to figure out how to write a backend, connect it to data sources or worse how to manage and scale it. By deploying StrongLoop’s LoopBack mobile backend-as-a-service (mBaaS) on Cloud Foundry it’s possible to take advantage of an open, private mBaaS on an open and scalable platform-as-a-service.
What is Cloud Foundry?
Unlike many cloud providers, Cloud Foundry is an open source PaaS, providing a choice of supported clouds, developer frameworks and application services. Cloud Foundry makes it faster and easier to build, test, deploy and scale mobile backends like StrongLoop’s LoopBack. It is an open source project and is available through a variety of private cloud distributions and public cloud instances.
Why run LoopBack on Cloud Foundry?
If you are a mobile developer looking to develop applications that need access to data that resides in the cloud and the datacenter, there’s quite a few advantages to running your own private mBaaS in the cloud:
LoopBack is open source and extensible at its core and with the over 41,000 available NPM community modules, the possibilities are almost limitless
Out-of-the-box, LoopBack connects to enterprise datasources like Oracle and MongoDB
LoopBack ships with an iOS SDK, so you won’t have to compromise on functionality or inherit a steep learning curve
Cloud Foundry lets you focus on your app not machines or middleware
Cloud Foundry manages the patching, load balancing and availability of your backend
If your app needs it (and let’s hope it does!), Cloud Foundry auto-scales on demand to make sure whether you are servicing one or tens of thousands of users – everyone is guaranteed to have a stellar user experience
Configuring for Cloud Foundry and StrongLoop
First step is to install and configure the CF tools on your dev machine:
1. Register at StrongLoop.com and download the StrongNode distro for your development environment.
2. Install the Cloud Foundry CLI common referred to as cf ( *you need Ruby 1.9.3 , OSX comes with Ruby v1.8.7 installed out of the box a small gist to help you with upgrade options for Mac)
$gem install cf
3. configuring your target ( you will need cf target, I’m using pivotal https://console.run.pivotal.io/register for this demo)
$cf target api.run.pivotal.io cf login <email> <password>
More information on Deploying Node.js Applications on CF
CF Push, For the Win
Build your LoopBack mBaaS on your local developer machine and push it to a Cloud Foundry PaaS
1.Create and Prepare your StrongLoop LoopBack Node application on your local machine
$mkdir CloudFoundryApp$cd CloudFoundryApp $slc lb api-example $cd sls-sample-app $slc install
2. Verify your LoopBack Mobile API tier is up and running by hitting the API explorer page on your local machine at http://localhost:3000/explorer
3.Push your StrongLoop Application to the cloud
$cf push my-new-app
Start Server, receive Open Node MBaaS
Now that your newly created StrongLoop server is up, let’s take a look at what you get and connect your Cloud Foundry hosted MBaaS to a native Mobile iPhone app
Since you have the ‘loopback-mobile-getting-started’ github repo on your local machine you can simply open the loopback iOS guide app located at /loopback-ios-app/loopback-ios-multi-model.xcodeproj with XCode.
Once the XCode Project is open you will need to modify your Adaptor endpoint to point to your server. Modify the
_adapter = [LBRESTAdapter adapterWithURL:[NSURL URLWithString:'http://localhost:3000';]]; in the AppDelegate.m. Change the ‘localhost’ address to point to your ip address.
Hit command R in XCode and walk through the walk the guide application instructions.
If you would like to find some more examples on how to integrate native iOS applications with LoopBack make sure and check out the http://github.com/strongloop-community/loopback-examples-ios , where you will find a UITableView, MapView and custom method call samples.
Now that you have your StrongLoop Suite ( StrongNode, StrongOps and LoopBack ) up and configured you can start building out your mobile client application. You can identify ‘hot spots’ and latency with StrongOps or look for stress inside your node.js server application code. You can customize your services and data by extending the open source Node LoopBack API tier with custom code or NPM modules from the community.