Skip to content

mschmulen/ios-mobile-server-with-node-and-digitalocean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

#Using a Digital Ocean Droplet for on demand mobile backend

Image

The tagline "Digital Ocean provides blazing fast SSD cloud servers at only $5/month" does not due Cloud provider Digital Ocean justice.

In addition to the performance of the server instance (a droplet in Digital Ocean lingo).

Digital Ocean has become a favorite of developers for the following reasons:

  • low cost performance
  • Droplets standup fast, very fast ( 59 seconds fast )
  • Static external IP address for every droplet
  • Droplet's disk, RAM, and IP address are all reserved while the droplet is off
  • Snapshot feature allows you to save the droplet after you have destroyed the instance.
    • Preserving costs and making for a fast standup of your configuration for developer Sandbox preserving costs)
    • You will be able to create a new droplet from the snapshot image anytime to bring it back online.

##Creating and Configuring your Digital Ocean Virtual Machine

  1. Login to Digital Ocean and Create your droplet in less than a minute. Image

  2. Configure your host name Image

  3. Select your configration size. Image

  4. Select your region. Image

  5. Select your Image, in this walk through I will create it from Linux Ubuntu 12.04 x32. However you can start from an "Application" image such as Docker or WordPress, or from one of your own "SnapShot" image ( these are great for standing up a dev stage fast). Image

  6. Count to 60. Image

Standing up your Node.js mobile services with StrongLoop

Image

Now that your Virtual Machine droplet is up, check your email for your login, password and IP Address. The email will look like:

Yay! Your new Droplet has been created!

You can access it using the following credentials:

IP Address: 192.111.111.111
Username: root
Password: yanzfapgryvh
  1. From the terminal ssh to your new instance with `ssh root@192.111.111.111' and the password provided.
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-24-virtual i686)

 * Documentation:  https://help.ubuntu.com/
Last login: Fri May  3 18:28:34 2013
root@MobileServices:~#
  1. Now Lets configure the server with the StrongLoop Node distro, to make this step easier I created a small install script to install dependencies get you up quickly.

The script will update apt-get and install some of the usual suspects: python-software-properties, vim git subversion curl , memcached, build-essential, etc ( feel free to modify for your specific configurations) s. Additionally it will download and install the latest StrongLoop Debian distro from StrongLoop. Finally the script will create a /var/apps folder for you to hold your Node applications.

To run the script on your server:

  1. copy the contents of script.sh to your copy buffer with CMD+Copy

  2. From the terminal you can simply 'wget -O install.sh http://raw.github.com/mschmulen/ios-mobile-server-with-node-and-digitalocean/master/install.sh' Just copy past the script to your command line with.

  3. and then run the command with 'chmod +x script.sh; ./script.sh'

  4. Stand Up your LoopBack Mobile Server with the following commands

cd /var/apps

slc lb project loopback-server
cd loopback-server
slc lb model product
slc lb model store
slc lb model customer
slc install

you can verify the installation by starting your server with 'slc run app.js' and open a web browser on your local machine to the servers address and the default port http://192.111.111.111:3000/explorer

Now that you have a loopback mobile server with mobile models for product, store, and customer you can use them from your mobile application development workflow.

Integrating your Native iOS App

image

Now we can integrate a mobile application with our Digital Ocean SSD virtual machine and the LoopBack Node API server using the native LoopBack iOS SDK.

The best part is we don't even need to install Node or LoopBack on our local dev machine ( although this is useful if you want to run your development cycle on your local box when your disconnected from the network ). You can download the iOS .Framework SDK directly from (http://github.com/strongloop-community)[http://github.com/strongloop-community/loopback-ios-sdk] and start with your process.

  1. Clone the iOS example apps on your local machine
git clone git@github.com:strongloop-community/loopback-examples-ios.git
  1. Open the TableView example in XCode ( you should also checkout the MapView and Remote Procedure projects as well)

You can open the XCode project with the following command on your local dev machine.

open loopback-examples-ios/ios-tableview-simple-example/tableview-example.xcodeproj
  1. Update the endpoint URL to match you newly instantiated Digital Ocean virtual machine IP address, my modifying the AppDelegate.m file in the tableview-example group:

change :

+ (LBRESTAdapter *) adapter
{
    if( !_adapter)
        _adapter = [LBRESTAdapter adapterWithURL:[NSURL URLWithString:@"http://localhost:3000"]];
    return _adapter;
}

to

+ (LBRESTAdapter *) adapter
{
    if( !_adapter)
        _adapter = [LBRESTAdapter adapterWithURL:[NSURL URLWithString:@"http://192.111.111.111:3000"]];
    return _adapter;
}
  1. Run the project in the simulator by with the ( ⌘ + R ) hot key or press the play triangle in the top left corner of XCode.

The Examples app will leverage the "product" model that you defined when creating your LoopBack Node Server instance, so you can simply explore the code in the ViewController.m file to see how to Create, Read, Update and Delete Mobile defined models from your Objective-C iOS mobile Application.

There is no need to define a static model schema, since LoopBack will allow the Mobile Developer to define the Model attributes dynamically from the mobile Application.

Make sure and checkout the LoopBack documentation on how to leverage the built in filter functions and also to Connect your Node.js mobile objects to additional connectors or Server data stores such as MongoDB or Oracle.

'Snapshot' your Droplet for on demand mobile backend

Now that you have your StrongLoop Loopback server configured and your mobile application connected you can take advantage of Digital Oceans Snapshot feature. This makes it fast and easy to spin up a mobile backend in a few seconds with zero server configuration.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages