Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 18 Current »

Prerequisites


Our examples make use of NodeJS and MongoDB, so be sure the have them installed and have mongo running on your machine.

We recommend downloading NodeJS, MongoDB, Nginx and NPM via Homebrew (Mac) or APT-GET (Ubuntu) 

We'll use Node to write our code, Mongo as our database, Nginx as our web server, load balancer and for upstream and finally NPM as our nodejs package manager.



         

                  


Installation


Now that we have all technologies we're going to use, let's go ahead and download the Utilities & Examples and go through them step by step.

The Utilities contains CLI commands to bootstrap some database information so that the examples can run.

Downloading the Utilities & Examples has never been easier, simply use NPM.

Downloading Components
# create a directory to install the components in it
> mkdir -p /opt/soajs/node_modules
> cd /opt/soajs/node_modules
# install the components
> npm install soajs.utilities


Hosts File


Add the following entry to your hosts file:

> vim /etc/hosts
# add the below line in your hosts file
127.0.0.1 test-api.mydomain.com


Nginx


Go to your Nginx configuration directory:

  • Mac: /usr/local/etc/nginx
  • Ubuntu: /etc/nginx

Create a new file called upstream.conf in folder conf.d

Upstream configuration
# upstream all traffic arriving from port 80 to port 4000
upstream soajs.controller {
  server 127.0.0.1:4000;
}

Create a new file called api.conf in folder sites-enabled

new server
# create new server test-api.mydomain.com that listens on port 80 and redirects to soajs.controller located in upstream.conf
server {
  listen       80;
  server_name  test-api.mydomain.com;
  client_max_body_size 100m;
  location / {
    proxy_pass 		    http://soajs.controller;
    proxy_set_header   	X-Forwarded-Proto 	    $scheme;
    proxy_set_header   	Host             		$http_host;
    proxy_set_header   	X-NginX-Proxy     	    true;
    proxy_set_header   	Connection        	    "";
  }
}

Once these files are created, restart nginx.

Restart Nginx
# stop nginx
sudo nginx -s stop


# start nginx
sudo nginx

This will instruct your web server NGINX to accept calls made to test-api.mydomain.com on port 80 and upstream them to port 4000 thus invoking the controller on IP 127.0.0.1



Utilities Parameters



Parameter
Key
Mandatory
Description
Default Values
FilefyesThe name of the file to be loaded-
HosthnoThe host machine (IP Address)127.0.0.1
Port NumberpnoThe port number on which MongoDB is listening27017
UsernameunoThe username required for the database authentication-
PasswordwnoThe password required for the database authentication-
Authentication Databasea noThe name of the database to which the user is authenticated-
Prefixinothe prefix of the db if one was set in the installation-
Patchxnoparameter to denote whether or not the command is to patch the database (can only be true or false)false

NOTE: If you set up Mongo with authentication then username, password, and authentication database must be provided.


  • No labels