Api

Description

Backend API build with Nest Framework.

This project uses @nestjsx/crud to simplify and standardize the REST API

Built with

Component

Using

Descrption

Base

ORM

CRUD

File Upload

Validation

Documentation

Authentication

Testing

Code Style

Development

Run

Postgres

start Postgres

# start local postgres
docker-compose up postgres
docker-compose up -V postgres #remove volumes

# start local keycloak
docker-compose up keycloak

# stop local postgres before restart again
docker-compose down
docker-compose down -v #remove volumes

if error The container name "/postgres" is already in use by container, remove orphan container.

docker ps -a
docker rm 82be5234c94a

connect Postgres running on local k8s

$ POD_NAME=$(kubectl get pods  -lapp=postgres -o jsonpath='{.items[0].metadata.name}')
$ kubectl port-forward $POD_NAME 5432:5432

Run Dev Mode

# start in watch mode
ng serve api
# to turn on logging for `request`
NODE_DEBUG=request ng serve api
DEBUG=typeorm:* ng serve api
# optionally you can run with prod env(environment.prod.ts) for tesrting! use this for testing only.
ng serve api --prod

Run Prod Mode

# clean dist first
npx rimraf dist
# then build
ng build api --prod
# then run
node dist/apps/api/main.js

API URL: http://localhost:3000

Swagger Docs URL: http://localhost:3000/docs

Build

build for production env

ng build api --prod
# or
yarn workspace @ngx-starter-kit/api build:prod

Commands

# to run custom commands, `check api:typeorm in angular.json`
ng run api:typeorm

Generate

scaffolding nest artifacts For more details checkout playbook

# check of nest installed
nest info

# scaffold auth module
nest g module app/auth  --dry-run
nest g controller auth app/auth --flat --dry-run
nest g service auth app/auth --flat --dry-run
nest g class user.entity app/auth --no-spec --dry-run
nest g class auth.exception app/auth --no-spec --dry-run

Unit Test

coverage will be generate in coverage/apps/api

# unit test only changed
ng test api --onlyChanged
# generate coverage
ng test api --codeCoverage
# test in CI env
ng test api --runInBand

E2E Test

ng e2e api
# e2e test with watch mode
ng e2e api --watch
# e2e test in CI env
ng e2e api --forceExit --detectOpenHandles

Health

check API App health

https://api.kashmora.com/live https://api.kashmora.com/ready

Reference

Last updated