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.
Code Block | ||||
---|---|---|---|---|
| ||||
# 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:
Code Block | ||
---|---|---|
| ||
> 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
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# 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
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# 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.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# 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
...
...
...
...
...
...
Info | ||
---|---|---|
| ||
Check out SOAJS Installer [click here] |