This hybrid Android app project is built using the Ionic framework, meaning that the front-end of the app is built using a combination of HTML, Sass, and TypeScript. The database used is PostgreSQL, and the web service used to query the database is built using NodeJS.
During development, in order for the API function calls to work, add and enable the Allow-Control-Allow-Origin: * Chrome extension to your browser. This is needed for cross-origin resource sharing (CORS), as the front-end and back-end of the project are hosted on different servers.
This project has several dependencies (including bluebird, express, jade). Compiled below are the modules that should be installed in the project. Run all commands from the root folder.
Ionic is the hybrid app framework on which this project is being built on. Cordova is used for building apps into native projects for Android. Run this in the root folder of the project.
$ npm install -g cordova ionicExpressJS is the web application framework for Node.js, designed for building web applications and API's. In this project, it is used to test API's.
$ npm install express-generator@4 -g
$ express
$ npm installpg-promise makes connection management with databases much easier, providing a powerful query formatting engine and support for automated transactions.
$ npm install pg-promise@5 --saveBluebird provides a way of working with Promises in NodeJS, allowing project developers to control the flow of their asynchronous code.
$ npm install bluebird@3 --saveFor more information, you can read more on the Ionic Facebook Native docs. The Facebook plugin should then be added to the app's module.
$ ionic cordova plugin add cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="myApplication"
$ npm install --save @ionic-native/facebookFinally, please be sure to install the dependencies in the root folder of the project.
$ npm installRun npm install in the root folder to install the Express dependency. Run the npm start command in the root folder. You can then test the API endpoints in http://localhost:3000/. Note that the app will not probably load information unless this database is running.
$ npm startOn web, serve the Ionic project in the browser. Run the ionic serve command in the root folder. You can then run the project in http://localhost:8100/. Reminder: Make sure you have activated the web service in the Express environment.
$ ionic serveBuilding on the Android device is a little complicated, as the Android device will need to be able to communicate with the Clustr web service. Reminder: Make sure you have activated the web service in the Express environment.
First, connect your Android device to your computer via a USB cable. For the app to properly build on the device, turn on USB Debugging as well as USB Tethering in your Settings.
Run ipconfig in your computer's terminal to retrieve the IPv4 Address of your wireless connection, likely going to be formatted similarly to 192.168.XX.XXX, where each X represents whatever numbers are in your IP address.
$ ipconfigIn all API .js files (e.g. users.js or activities.js), which are found in the api folder, change your database initialization code to the following, where host is your IP address and username and password are the administrative credentials you assigned to your PostgreSQL database. Note that major updates to this repository are accompanied with a clustr.pgsql file, such that you are able to replicate the results of the app at a certain point in time.
var db = pgp({
host: '192.168.XX.XXX',
port: 5432, // Or your desired port
database: 'clustr',
user: 'postgres',
password: 'c1ustR!17'
})
Additionally, change the following line stored in the app.config.ts file, found in the src > app folder, to the following.
public server : string = 'http://192.168.XX.XXX:3000/';
Then, so that PostgreSQL will allow access to a user who has the encrypted password, add the following line as the first uncommented line in your pg_hba.conf file (located in the PostgreSQL folder created upon installation, located in your Program Files by default).
# TYPE DATABASE USER ADDRESS METHOD
host all all 192.168.XX.XXX/0 md5
Finally, to run on an Android device (note that this project is developed for Android), enter the following commands in the root folder to build and run the app.
$ ionic cordova platform add android
$ ionic cordova run android