Bluemix supports IBM's MobileFirst strategy by allowing you as a mobile developer to quickly incorporate pre-built, managed, and scalable cloud services into your mobile applications without relying on IT involvement. You can focus on building your mobile applications rather than the complexities of managing the back end infrastructure.
When you create a Mobile Cloud Starter application, Bluemix provisions multiple services under a single application context. Your mobile application is given access to the following mobile services: Mobile Application Security, Push, and Mobile Data.
The Mobile Cloud Starter application also contains the default Cloud Code Template which includes following functionalities:
For more details, please read the code comments in app.js.
IBM Cloud Code Template is running in node.js
runtime. To develop your own code, open the app.js
and edit the content with any text
editor. There is no restriction on writing the node code, which means you can use any third party modules available on the web.
The cloud code template is using express 4.x
as the web application framework and Router
api to moduralize REST endpoints. To extend it, you might:
people.js
file and place it under lib
folderOpen the people.js
file and write a mini express app with Router
api:
var people = require('express').Router();
people.get('/', function(req, res, next) {
});
people.post('/', function(req, res, next) {
});
people.put('/', function(req, res, next) {
});
people.delete('/', function(req, res, next) {
});
module.exports = exports = people;
Map the mini express app you have just created to the cloud code context root in the app.js
app.use(ibmconfig.getContextRoot(), require('./lib/people.js'));
IBM Cloud Code Template is a standard node.js
application. You can test it on your local workstation with the Bluemix environment context.
node.js
runtimenpm install --production
to install the dependent modulesnode app.js
http://localhost:3000/yourapplicationroute/v1/apps/yourapplicationid/*
For example, static file can be access at
http://localhost:3000/yourapplicationroute/v1/apps/yourapplicationid/public
To be able to test your application locally with Bluemix environment context, you need to:
Create a Mobile Cloud Starter application on Bluemix with name cloudcodetest
Download and install the Cloud Foundry CLI
Run cf login
to log into your Bluemix orgnization and space where your Bluemix application is located
Create or download the manifest.yml
and place it with app.js
. The manifest.yml
should look like:
applications:
- services:
- testnewmab:MAS
- testnewmab:Push
- testnewmab:MobileData
disk_quota: 1024M
host: cloudcodetest
name: cloudcodetest
command: node app.js
path: .
domain: mybluemix.net
instances: 1
memory: 128M
Then run node app.js
to start your application. The Bluemix environment context for application cloudcodetest
will be automatically retrieved and added to your application.
node-inspector
as a global modulenode-debug app.js
Cloud Foundry CLI
cf push ${yourAppName}
to deploy the app to Bluemix.http://${yourAppHost}.mybluemix.net/${yourAppHost}/v1/apps/${applicationId}/*
For example, static file can be access at
http://cloudcodetest.mybluemix.net/cloudcodetest/v1/apps/33819e7d-31b3-4108-9f6a-18b117919512/public