The back end is built in Node JS and handles the following:
- Writing of data from the mobile app to the Cloudant DB.
- Writing of video from the mobile app to IBM Cloud Object Storage (COS).
- Reading of data by the Fair Change Website in order to populate the map view and also to view further data related to an incident / video URL.
In this tutorial, you will:
- Learn how to connect Cloud Object Storage and Cloudant services to the back-end application.
- Populate data into Cloudant database
- Test and run this app locally
- Deploy application to IBM Cloud
To complete the steps in this tutorial you need:
- Sign up for an IBM Cloud Account
- Provision Instance of Cloud Object Storage on IBM Cloud
- Provision Instance of Cloudant on IBM Cloud
This tutorial will take you about 30 minutes to complete.
The following assumes you have gone through the prerequisites.
-
Clone the repository and cd into backend folder.
-
Make a
configuration.json
file
touch configuration.json
- Copy the following json into your newly created
configuration.json
file and add in the following information from your Cloudant (Step 6) and your Cloud Object Storage (Step 6) services
{
"fairChangeDb": {
"apikey": "<Cloudant apikey>",
"host": "<Cloudant host> ",
"iam_apikey_description": "<Cloudant iam_apikey_description>",
"iam_apikey_name": "<Cloudant iam_apikey_name>",
"iam_role_crn": "<Cloudant iam_role_crn>",
"iam_serviceid_crn": "<Cloudant iam_serviceid_crn>",
"url": "<Cloudant url>",
"username": "<Cloudant username>",
"dbName": "<Cloudant dbName>"
},
"logging": {
"level": "debug",
"consoleEnabled": true,
"piiFilter": [
"decryptedToken",
"authorization",
"hostname"
]
},
"cloudObjectStorage": {
"bucketName": "<cloudObjectStorage bucketName>",
"apikey": "<cloudObjectStorage apikey>",
"cos_hmac_keys": {
"access_key_id": "<cloudObjectStorage access_key_id>",
"secret_access_key": "<cloudObjectStorage secret_access_key>"
},
"endpoints": "<cloudObjectStorage endpoints>",
"endpoint": "s3.us-east.cloud-object-storage.appdomain.cloud",
"iam_apikey_description": "<cloudObjectStorage iam_apikey_description>",
"iam_apikey_name": "<cloudObjectStorage iam_apikey_name>",
"iam_role_crn": "<cloudObjectStorage iam_role_crn>",
"iam_serviceid_crn": "<cloudObjectStorage iam_serviceid_crn>",
"resource_instance_id": "<cloudObjectStorage resource_instance_id>"
}
}
- Populate your database with data. Map data can be found here
npm install couchimport
export COUCH_URL=<Cloudant url>
export IAM_API_KEY=<Cloudant apikey>
export COUCH_DATABASE=<Cloudant dbName>
cat ../website/components/common/map.dataBetter2.json | ./node_modules/.bin/couchimport --database <Cloudant dbName> --type jsonl
Once the data is populated you should see :
If you go back to your cloudant database you should see that the data has been imported
-
Once data has been imported, install the dependencies:
npm install
-
Run the application:
npm run dev
-
View the backend data in a browser at
http://localhost:3000/api/getIncidents
http://localhost:3000/
should give you the Fairchange API docs
Congratulations, you have the backend up and running locally! Now you can follow these instructions for setting up the web application's front end running locally
-
Go to
backend
folder and edit manifest.yml file. Change the name field to something uniqe. Once the name is changed run build.npm run build
-
Log in to IBM Cloud with the IBM Cloud CLI:
ibmcloud login --sso
-
Target a Cloud Foundry organization and space:
ibmcloud target --cf
-
Deploy the application
ibmcloud app push
-
View the application online at the app URL. For example, appName-Backend.mybluemix.net.
- View the application from IBM Cloud by searching for your app's name and then
Visiting App URL
Congratulations, you have the backend up and running on IBM Cloud! Now you can follow these instructions for setting up the web application's front end running on IBM Cloud