- Vicinity neighbourhood manager: localhost:8000
- client: localhost:8000
- server: localhost:3000
- Facility stub:
- client: localhost: 8010
Sometime you need to create simple backend application, e.g. Facility manager application which reads data from GATEWAY api of Vicinity Neighbourhood manager.
In this example the backend application which reads data directly only from gateway api.
Architecture will be as follows:
- SPA by AngularJS+Bootstrap with expressjs/nodejs.
- Data layer will be implemented by VNM.
- Authentication is using JWT.
Pre-requisits: npm, nodejs [http://nodejs.org/], git [https://git-scm.com/] installed.
- Create AngularJS from angularjs/nodejs seed. Clone AngularJS in your project directory. If you want manage stub under VICINITY git repository, you should store it in "stubs" directories.
cd vicinity/stubs
git clone --depth=1 https://github.com/angular/angular-seed.git facility
remove .git
directory in stubs\facility
directory
- Instal node and bower packages and put them under version control.
cd vicinity/stubs
cd facility
npm install
git add .
git status
Note, bower packages are installed by npm install.
- Configure port for your stub.
- Open
package.json
file in root stub directory (e.g.vicinity\stubs\facility\package.json
- Choose unoccupied port for your stub.
- Edit
'start'
script value:"start": "http-server -a localhost -p 8030 -c-1",
- Update list of port in this readme.
- Adding bootstrap framework.
- Open
bower.json
file instubs\facility
directory. - Add bootstrap dependency.
{
"name": "angular-seed",
"description": "A starter project for AngularJS",
"version": "0.0.0",
"homepage": "https://github.com/angular/angular-seed",
"license": "MIT",
"private": true,
"dependencies": {
"angular": "~1.4.0",
"angular-route": "~1.4.0",
"angular-loader": "~1.4.0",
"angular-mocks": "~1.4.0",
"html5-boilerplate": "~5.2.0",
"bootstrap": "3.3.6"
}
}
- Run
npm install
instubs\facility
directory. - Put files under version control "git add ."
- Adding boostrap in template.
- Download bootstrap template such as (https://github.com/puikinsh/gentelella/releases)
- Import index.html and necessary supporting files in ```stubs\facility\app.
- run application using
npm start
- Install node-debugger package in ATOM editor
- Atom -> Preferences -> Install
- Search "node-debugger"
- Install
- Configure node-debugger package in ATOM editor
- Atom -> Preferences -> Community Packages -> node-debuger
- Settings:
- Set "Node Path" to local location of the node executable (e.g.
which node
) - Path to
vicinityManager/server/bin/www
(e.g. Right click on file in left menu and 'Copy path')
- Set "Node Path" to local location of the node executable (e.g.
- Usable commands
'node-debugger:start-resume' (F5)
'node-debugger:debug-active-file' (ctrl-F5)
'node-debugger:stop' (shift-F5)
'node-debugger:toggle-breakpoint' (F9)
'node-debugger:step-next' (F10)
'node-debugger:step-in' (F11)
'node-debugger:step-out' (shift-F11)
'node-debugger:attach'
- GIT - [https://git-scm.com/]
- NodeJS - [http://nodejs.org/]
- mkdir /var/www
- cd /var/www
- git clone https://jalmela@bitbucket.org/bavenir/vicinity.git
- mv /var/www/vicinity-neighbourhood-manager /var/www/vicinity
- cd /var/www/vicinity/vicinityManager/client/app
- sudo vim env.js
- Comment all the lines except the first
- Add at the bottom: this._env.apiUrl = "http://:"
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Output
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
Next, we have to add the MongoDB repository details so apt will know where to download the packages from. Issue the following command to create a list file for MongoDB.
- WARNING: It may change depending on the Linux distribution
- echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
- sudo apt-get update
- sudo apt-get install -y mongodb-org
- sudo systemctl enable mongod.service
- sudo systemctl start mongod
- sudo systemctl status mongod – Check it runs properly
- Mkdir /data/db
- Chown -R mongodb:mongodb /data/db
- Chown -R mongodb:mongodb /var/lib/mongodb
- Storage --> dbPath: /data/db
- SystemLog --> path: /var/log/mongodb/mongod.log
- sudo npm install -g bower
- cd /var/www/vicinity/vicinityManager/client
- sudo bower install --allow-root
- sudo npm install
Install NGINX -- https://www.nginx.com/resources/wiki/start/
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get install nginx
- cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
- sudo service nginx reload
- sudo touch /etc/nginx/sites-available/vicinity
- sudo touch /etc/nginx/sites-enabled/vicinity
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/vicinity/vicinityManager/client/app;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
- sudo rm /etc/nginx/sites-enabled/default
- sudo service nginx restart
- cd /var/www/vicinity/vicinityManager/server
- sudo npm install
- npm install –g forever
- sudo mkdir /var/run/forever
- sudo touch /etc/init.d/vcnt_server
- sudo chmod a+x /etc/init.d/ vcnt_server
- sudo update-rc.d vcnt_server defaults
- Update environmental variables within the script below. Use the corrensponding information for your deployment.
#!/bin/bash
### BEGIN INIT INFO
# If you wish the Daemon to be lauched at boot / stopped at shutdown :
#
# On Debian-based distributions:
# INSTALL : update-rc.d scriptname defaults
# (UNINSTALL : update-rc.d -f scriptname remove)
#
# On RedHat-based distributions (CentOS, OpenSUSE...):
# INSTALL : chkconfig --level 35 scriptname on
# (UNINSTALL : chkconfig --level 35 scriptname off)
#
# chkconfig: 2345 90 60
# Provides: /var/www/vicinity/vicinityManager/server/bin/www
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: forever running /var/www/vicinity/vicinityManager/server/bin/www
# Description: /var/www/vicinity/vicinityManager/server/bin/www
### END INIT INFO
#
# initd a node app
# Based on a script posted by https://gist.github.com/jinze at https://gist.github.com/3748766
#
if [ -e /lib/lsb/init-functions ]; then
# LSB source function library.
. /lib/lsb/init-functions
fi;
pidFile="/var/log/vicinity/vcnt_server.pid"
logFile="/var/log/vicinity/vcnt_server.log"
outFile="/var/log/vicinity/vcnt_server.out"
errFile="/var/log/vicinity/vcnt_server.err"
command="node"
nodeApp="/var/www/vicinity/vicinityManager/server/bin/www"
foreverApp="forever"
### EXPORT environmental variables
# PORT
export PORT=3000
# MONGO DB URL
export VCNT_MNGR_DB=<YOUR MONGO CONNECTION STRING>
# Comm Server URL and token
export commServerToken=<YOUR COMM SERVER ACCESS TOKEN>
export commServerUrl=<YOUR COMM SERVER URL>
# JWT Token secret
export jwtTokenSecret=<YOUR JWT SECRET>
# Semantic Repository URL
export semanticRepoUrl=<YOUR SEMANTIC REPOSITORY URL>
start() {
echo "Starting $nodeApp"
# Notice that we change the PATH because on reboot
# the PATH does not include the path to node.
# Launching forever with a full path
# does not work unless we set the PATH.
PATH=/usr/local/bin:$PATH
export NODE_ENV=production
PORT=$PORT VCNT_MNGR_DB=$VCNT_MNGR_DB $foreverApp start --pidFile $pidFile -l $logFile -o $outFile -e $errFile -a -d -c "$command" $nodeApp
RETVAL=$?
}
restart() {
echo -n "Restarting $nodeApp"
$foreverApp restart $nodeApp
RETVAL=$?
}
stop() {
echo -n "Shutting down $nodeApp"
$foreverApp stop $nodeApp
RETVAL=$?
}
status() {
echo -n "Status $nodeApp"
$foreverApp list
RETVAL=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit $RETVAL
- sudo mkdir /var/log/vicinity
- sudo touch /var/log/vicinity/vcnt_server.out
- sudo touch /var/log/vicinity/vcnt_server.log
- sudo touch /var/log/vicinity/vcnt_server.pid
- sudo touch /var/log/vicinity/vcnt_server.err
- sudo service vcnt_server start
- Create dB vicinity_neighbourhood_manager in Mongo
- Create the collections user and useraccounts
db. useraccounts.insert({
"name" : "admin",
"cid" : "admin",
"businessId" : "00000000",
"skinColor" : "black",
"location" : "test",
"status" : "active"
})
- db.useraccounts.find({organisation: organisationName}).pretty()
db.users.insert({
"email" : "admin@admin.com",
"occupation" : "admin",
"name" : "admin",
"location" : "test",
"authentication" : {
"hash" : REQUEST FIRST PASSWORD TO BAVENIR,
"principalRoles" : [
"user",
"devOps",
"administrator"
]
},
"accessLevel" : 1,
"cid" : {
"id" : < organisation MongoId >,
"extid" : "admin"
},
"status" : "active"
}
})
- db.useraccounts.update({'organisation': organisationName},{'accountOf': { $push:{'id': < user MongoId >, 'extid': "admin@admin.com" }}})
- Navigate your browser to the app domain and use the mail and password to do the first log in.