Skip to content

singletonsd/ravimoshark-apis-contract-app-nodejs

Repository files navigation

RAVIMOSHARK - APIS - CONTRACT - NodeJS APP

The main repository is hosted in gitlab.com/ravimosharksas but it is automatically mirrored to github.com/RavimoShark, gitlab.com/singletonsd, github.com/singletonsd, github.com/patoperpetua and to gitlab.com/patoperpetua. If you are in the Github page it may occur that is not updated to the last version.

Overview

This server was generated by the swagger-codegen project. By using the OpenAPI-Spec from a remote server, you can easily generate a server stub.

RUNNING SERVER

Be aware to setup the configuration of the database. It can be set by database user and password as ENVIRONMENT VARIABLES or to provide your own ormconfig.json file.

After setup database configuration and running the server using either way, you can access the api under:

http://localhost:8000/

To view the Swagger UI interface:

open http://localhost:8000/docs

USING DOCKER

To use this container with docker, just type docker-compose -f docker-compose/main.yaml up or execute the following script:

docker run -it --rm -e DB_PASSWORD= -e DB_USER=Ravimo2015 \
    -p 8000:8000 \
    registry.gitlab.com/ravimosharksas/apis/contract/app-nodejs/alpine:8-alpine-latest

DIFFERENT IMAGE FLAVORS

Docker images run using Docker Node Official Images and Docker Keymetrics PM2 Official Images.

You can choose to execute the server in two different operative systems:

  • alpine: it uses base image node:-alpine. Available versions:
    • 8-alpine
    • 10-alpine
  • stretch: it uses base image node:-stretch. Available versions:
    • 8-stretch
    • 6-stretch

USING NPM

To run the server, type:

npm install
npm start

DEFAULT API TOKEN

ENVIRONMENT VARIABLES

  • API_VERSION: api version image. Default: latest.
  • API_BASE: api base image (alpine or stretch). Default: alpine.
  • SWAGGER_URL: url of api.
  • APP_PORT: port to connect to the api. Default: 8000.
  • HOST_PORT: port to map to host. Default: 80.
  • DB_USER: user for database connection.
  • DB_PASSWORD: password for database connection.

API TOKENS

DATABASE CONNECTIONS

You can provide your own ormconfig.json file to connect with a database. Use the following example configuration to create that file and put it in the root folder.

{
   "name": "default",
   "type": "mssql",
   "host": "",
   "port": 1433,
   "username": "",
   "password": "",
   "database": "",
   "options": {
      "encrypt": true
   },
   "schema": "dbo",
   "synchronize": false,
   "logging": "WARN"
}

DEPLOYMENT

  • MASTER BRANCH:
    • It creates a docker image using the following tags:
      • ravimosharksas/apis/contract/app-nodejs:latest.
  • DEVELOP BRANCH:
    • It creates a docker image using the following tags:
      • ravimosharksas/apis/contract/app-nodejs:develop.

BRANCHING MODEL

  • Default branch when pull is DEVELOP.
  • Master branch is protected and it is not possible to push. Create a merge request instead.

GENERATE SERVER

Generates an nodejs server of the provided spec. It contains the following options inside a file called .env.swagger :

SWAGGER_API_SPEC=#location of spec, it can be local or url
SWAGGER_REPO=#repository name

It can be downloaded by:

mkdir -p scripts && \
curl -o scripts/swagger_binaries_downloader.sh -L https://singletonsd.gitlab.io/scripts/swagger/latest/swagger_binaries_downloader.sh && \
curl -o scripts/swagger_generate_angular.sh -L https://singletonsd.gitlab.io/scripts/swagger/latest/swagger_generate_nodejs.sh && \
chmod +x scripts/swagger_binaries_downloader.sh scripts/swagger_generate_nodejs.sh && \
./scripts/swagger_generate_nodejs.sh

GENERATE DOCKER IMAGES LOCALLY

You can create docker images locally by executing the following script:

npm run docker-download #only first time
npm run docker-generate #once download was executed.

TODO

  • Setup docker image.
  • Setup test environment.
  • Connect Database with an ORM.
  • Add lint rules.
  • Config TS.
  • Config Keyclock to authenticate.

© Singleton SD, France, 2019.