Skip to content

Repository files navigation

Green-API

A NestJS API for the Nebrija Green project

Project setup

Install required dependencies

$ npm install

Self-Signed Certificate for HTTPS

Generate a self-signed certificate used to enable HTTPS:

$ openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365 -nodes

Set up the environment files based on the .example files

# App Config
PORT=3000 (Leave as 3000 as the docker image exports this port)
TOKEN=(Admin token used to register new users for the first time)
JWT_SECRET=(Secret used to generate JWT)
# DB
DB_TYPE=postgres (Leave as postgres)
DB_HOST=(IP/Host name of the database, 'db' in prod specified on the docker compose)
DB_PORT=5432 (Leave as 5432)
DB_USER=(DB user)
DB_PASSWORD=(User password)
DB_DBNAME=(Database name)
DB_LOGGING=(Boolean to enable login for the DB)
# Docker
POSTGRES_DB=(Must be the same as DB_DBNAME)
POSTGRES_USER=(Must be the same as DB_USER)
POSTGRES_PASSWORD=(Must be the same as DB_PASSWORD)
PGADMIN_DEFAULT_EMAIL=(Must be a valid email address)
PGADMIN_DEFAULT_PASSWORD=(Access password to the pgAdmin portal)

Extensions and code style guides

# Required:
ESLint:          "dbaeumer.vscode-eslint"
# Recommended:
Better Comments: "aaron-bond.better-comments"
Container Tools: "ms-azuretools.vscode-docker"
Error Lens:      "usernamehw.errorlens"

The project uses eslint to enforce clean and consistent code style, and this its required for any person looking to contribute code.

Compile and run the project

# Run in development mode
$ ./dev.cmd
$ ./dev.sh

# Build and run production mode
$ ./build.cmd
$ ./build.sh

Project structure

> ./
│ dev.cmd/.sh        # Script to start the app and docker in dev mode
│ build.cmd/.sh      # Script to start the app and docker in prod mode
│ .env               # Environment used for dev.cmd/.sh
│ .env.prod          # Environment used for build.cmd/.sh
│ dockerfile         # Defines the docker image for the nest app
│ docker-compose.yml # Defines the docker stack for production
├┬> docker
│└ docker-compose.yml # Defines the docker stack for development
└┬> src
 │ # Modules     > Define what imports, exports. provider, etc the controller/service needs# Controllers > They are responsible of receiving and responding to requests# Services    > They contain the logic# Provider    > They are shared logic that can be injected to multiple services
 ├─> constants  # Contains definitions for constants, types, enums, etc
 ├─> database   # Provider for the logic related to connecting to a database
 ├─> hashing    # Provider for the hashing functionality for passwords
 ├─> middleware # Runs before processing requests
 ├┬> auth       # Runs after the middleware used to ensure logging and permission
 ├┬> modules    # Contains all endpoints (except auth related ones)
 ││ # this is the example structure of a sensor module
 │├─> entities # Holds the definitions of objects as they will be stored in the database
 │├─> dto      # Holds the definitions of what types and structure the API is expecting on requests
 ││ Sensor.module.ts
 ││ Sensor.controller.ts
 │└ Sensor.service.ts
 └ main.ts # App entrypoint

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages