Skip to content

Latest commit

 

History

History
125 lines (100 loc) · 5.85 KB

features.md

File metadata and controls

125 lines (100 loc) · 5.85 KB

DOCUMENTATION

DEVELOPMENT

Docker (optional)

  • Built on lightweight docker image "node:8-alpine" (see Dockerfile).
  • Command lines to launch docker images:
    • yarn docker:dev launch project in DEV mode.
    • more... (see package.json)

Requirements

Platforms:

  • Mainly tested on MacOS, node 14.7.x.
  • Also tested on Windows 10 (Powershell) with MongoDB, latest nodejs.

Require:

  • MongoDB - e.g. install: docker run -p 27017:27017 -v ~/mongo_data:/data/db mvertes/alpine-mongo

Good to have:

  • A client tool to manage data like Robo 3T.
  • VSCode Rest Client extension to run examples in "rest-client-examples.rest".

Environments

  • Env vars are declared in ".env" file (npm: dotenv-safe).
  • They are loaded into "config/vars" and exported to be used across the app.

Initialize DB Data

  • When launching in development mode, it will check if the default user1 not existed (New DB) to generate some dev data.
  • Example: ../src/api/utils/InitData.ts

Express

  • config/express.ts is where we set up the Express server.

SSL Self-signed Cert (for HTTPS localhost)

openssl req -x509 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=localhost' -extensions EXT -config <( \
   printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

FEATURES

Add a new Model

  • Model has Mongoose schema & default functions like: transform, list.
    • "transform" method: to sanitize mongoose results with ALLOWED_FIELDS (so we don't expose unneeded fields)
    • "list" function: to list data with pagination support (URL parameters).
  • Always export Model with Model.ALLOWED_FIELDS
  • Example: ...src/api/models/userNote.model.ts

Add a new API Route

  • Steps to create a new route:
    • src/api/routes/your-new-route.route.ts
    • src/api/controllers/route-controller.ts
    • src/api/routes/v1/index.ts - add your route here.
  • Example: ../src/api/routes/v1/user.route.ts (CRUD routes for user endpoints).

API Controller

API - URL Parameters

Registration / Authentication

Authorization / Permission Validation

  • auth.ts - handleJWT: validate: only the same logged in userId can call REST endpoints /userId/...

API - Upload File /upload/file

API - Forgot Password /forgot-password

Slack

  • Obtain your Slack Incoming Webhook (tie to a channel) from your Slack account & put it in .env file.
  • Example: ../src/api/controllers/auth.controller.ts (send slack a message after user registered (POST v1/auth/register))

Send Email

  • Using "nodemailer" to send email
  • Using "handlebars" to get email templates: welcomeEmail({ name: 'John Doe', email: 'emailexample@gmail.com' })
  • Obtain your Mailgun API Key & Email Domain (use sandbox domain name for testing) & put it in .env file.
  • Example: ../src/api/controllers/auth.controller.ts (send email after user registered (POST v1/auth/register))

UI Example

  • UI Example location: /ui
  • Using CRA (create-react-app).
    • Typescript, React-router, Axios, PostCSS, Tailwind. Components: Home, ItemView, Login.

Deployment

With Vercel: