/apierp1

Primary LanguageTypeScriptMIT LicenseMIT

Pointhub API Starter

Features

  • Compression Using gzip compression with Compression
  • CORS Cross-Origin Resource-Sharing enabled using Cors
  • Environment Variable using dotenv
  • Secure HTTP Headers using Helmet

Development Stack

Services

Directory Structure

PAPI-STARTER
├── build
├── coverage
├── node_modules
├── src
│   ├── assets
│   ├── config
│   ├── database
│   ├── middleware
│   ├── modules
│   │   └── example
│   │       ├── controller
│   │       ├── model
│   │       ├── use-case
│   │       ├── validation
│   │       └── router.ts
│   ├── services
│   └── test
│       ├── setup.ts
│       ├── teardown.ts
│       └── utils.ts
├── .env
├── .env.example
├── .env.text
├── .env.test.example
└── README.md

Contribution Guide


Database for development

Since transactions are built on concepts of logical sessions they require mechanics which are only available in a replica set environment.

Choose one of the options that you prefer

Installation

If you are using docker for installation, currently we cannot connect it to the local MongoDB database. So you should use an online database for development

With Docker

You still need to install dependencies locally to enable development features like eslint, prettier, and test.

cp .env.example .env
cp .env.test.example .env.test
npm install
docker-compose up

Without Docker

cp .env.example .env
cp .env.test.example .env.test
npm install
npm run dev

Setup Database

Add Validation Schema

node cli db:init

Seed Default Database

node cli db:seed

Testing

Setup Database Schema

node cli db:init --db-name="starterTestDB"

Testing all test case

npm run test

Testing specific file or folder

# Test specific file
npm run test -- src/modules/example/controller/create.spec

# Test specific folder
npm run test -- src/modules/example/controller

# Test example module
npm run test -- src/modules/example

(Optional) Running test from docker

  1. Check running container
docker ps
CONTAINER ID   IMAGE              COMMAND                  CREATED             STATUS                PORTS                                 NAMES
902293b368b3   papi-starter-api   "docker-entrypoint.s…"   About an hour ago   Up 11 minutes         0.0.0.0:3000->3000/tcp
  1. Access docker container using CONTAINER ID above
docker exec -it 902293b368b3 bash
  1. Run test inside docker container
node@902293b368b3:~/app$ npm run test

Deployment

docker build -t pointhub/papi-starter .