0.0.1 • Published 7 years ago

noojiapi.nooji.io v0.0.1

Weekly downloads
7
License
-
Repository
github
Last release
7 years ago
################################################################################
###                                                                          ###
###   _   _                   _   _                          _   _           ###
###  | \ | |                 (_) (_)                        | | (_)          ###
###  |  \| |   ___     ___    _   _   _ __ ___     ___    __| |  _    __ _   ###
###  | . ` |  / _ \   / _ \  | | | | | '_ ` _ \   / _ \  / _` | | |  / _` |  ###
###  | |\  | | (_) | | (_) | | | | | | | | | | | |  __/ | (_| | | | | (_| |  ###
###  |_| \_|  \___/   \___/  | | |_| |_| |_| |_|  \___|  \__,_| |_|  \__,_|  ###
###                         _/ |                        Noojimedia (c) 2016  ###
###                        |__/                                              ###
################################################################################

Nooji API - NoojiMedia, Inc. 2016

NOTE: manual modifications to node_modules/loopback-api-testing/index.js

Allows for titles to be added to each test array (within each file)

the title must be the first element in the array

{"title": "This is the test title"}

Modifications needed:

on line 13

var testTitle = 'Loopback API';

line 27 (above the describe block)

if(conf[0].hasOwnProperty('title')){
  testTitle = conf[0].title;
  conf.shift();
}

describe(testTitle, function() {

Allows for descriptions to be added to the default loopback description

the description variable must be added to the json test block

{
  "description": "More clarification on test description",
  "method": "GET",
  ...
}

Modifications needed:

line 53 (where description is being instantiated)

var description = c.hasOwnProperty('description') ? c.description+'\n\t' : '';
description += 'should respond '+c.expect+' on '+authenticationDescription+' '+c.method+' requests to /'+c.model;

The project is generated by LoopBack.

TOC

Setup and installation

Pre-requirements

  • git and at least read permission for the repository
  • node install v6.8.0 or later
  • npm v3.10.8 or later

Installation

$ git clone git@github.com:gitnooji/nj-api.git

$ npm install

$ npm start

> noojiapi.nooji.io@0.0.1 start /Users/adelonga/Desktop/nooji/nj-api
> node .

Web server listening at: http://0.0.0.0:3001
Browse your REST API at http://0.0.0.0:3001/explorer

Post installation tests

The command below is a simple test to make sure the test framework is operational

$ npm run test-mocha

Now run basic unit tests to make sure the api is responding properly

$ npm test

Deploying API to dev server

Run the API on port 3001 to view the explorer (use complete path to noojiservers.pem)

$ ssh -i "/Users/adelonga/Desktop/nooji/certs/aws_pem/noojiservers.pem" ubuntu@ec2-54-149-183-160.us-west-2.compute.amazonaws.com

$ cd nj-api

$ git pull origin development

$ forever stopall

$ forever start server/server.js

congratulations you now have a working API at http://dev-api.nooji.io:3001/explorer/

Docker configuration and Setup

Build the docker image

From the root folder of the project.

$ docker build -t nj-api .

You should see similar output as below

Sending build context to Docker daemon 92.74 MB
Step 1 : FROM mhart/alpine-node:6
 ---> d9363f62a6ac
Step 2 : WORKDIR /src
 ---> Using cache
 ---> e2b103b82a95
Step 3 : COPY . .
 ---> Using cache
 ---> 7b47d6aa7f52
Step 4 : RUN npm install
 ---> Using cache
 ---> 3fe0b5f56dff
Step 5 : EXPOSE 3001
 ---> Using cache
 ---> 493099bc6a4b
Step 6 : CMD node server/server.js
 ---> Using cache
 ---> 8b83b43876a1
Successfully built 8b83b43876a1

you now have an image called nj-api

You are able to run this image using the following, replace the path to the certs mounted volume with the path to the certs folder. (use this when the ports defined in Dockerfile are available on your machine)

docker run -v /Users/adelonga/Desktop/nooji/certs/:/certs -P -t nj-api

If you wish to run the docker environment using your locally checked out version of the codebase (use this to remap the port/s, 3001, defined in Dockerfile to available ports on your machine, 3000)

docker run -v /Users/adelonga/Desktop/nooji/certs/:/certs -v $(pwd):/src -p3001:3000 -t nj-api

will run the server but overlay the current folder

Scripts

The following scripts are defined in package.json

Running

  • $ npm start (starts api server locally on port 3001)

Linting

  • $ npm run lint (apply lint rules)

Testing

  • $ npm run test-mocha (smoke test to make sure mocha is configured)
  • $ npm test (runs unit-tests then applies lint rules)