Skip to content

Server Development

The apps server consists of 2 major components

API
A NestJS rest api to handle communication between the app and backend database

Stack
A set of docker containers to run all backend services, including postgresDB, matomo analytics, metabase and various other tools

API development

Requires postgres13 installed locally

  1. Set environment variables

    cp packages/api/.env.example packages/api/.env
    
    Ensure API_BASE_PATH="" to allow running standalone (as opposed to part of full stack)

  2. Ensure the named POSTGRES_USER specified in .env also exists on postgres database with admin privileges. More info on creating users using PGAdmin4 can be found in this Google Doc

  3. Serve api

    yarn workspace api start:watch
    

    This will start a local api server alongside interactive documentation for testing endpoints This can be found on localhost:3000

    Note

    If postgres is not configured to start at boot time, as seems to be the case by default on macOS, then you must manually start it before serving the API. In order to start postgres running in the background, run pg_ctl -D /usr/local/var/postgres start.

    Example Docs - endpoints can be viewed and triggered with parameters

  4. Interact with app. By default any app running locally via yarn start will target the localhost api, so in-app operations such as contact field syncing can be tested in the same way as production

API Tests

E2E tests can be run via

yarn workspace api test:e2e
If developing tests an option --watch flag can be added at the end to live-reload

An additional admin user will need to be created on the local db as an alternative to the postgres admin. This will also require creation of a database to support initial bootstrap connection

username: test_admin
password: test_admin

database: test_admin

In order to run only a subset of tests filters can be used, e.g. to only run the app_user specs a testNamePatter filter flag can be used:

yarn workspace api test:e2e -t app_user

Stack development

Requires docker desktop installed locally

  1. Configure .env variables as per packages\server\README.md Ensure API_BASE_PATH="/api" to allow running as part of full stack

  2. Build api

    yarn workspace api docker:build
    

  3. run server stack

    yarn workspace server start
    
    NOTE - if users need to be configured then this can be done using the stack PGAdmin available at localhost:5050 with a connection host name db (instead of localhost)

  4. Interact with app Update the API_ENDPOINT specified in src\app\shared\services\server\interceptors.ts to target docker stack in development, i.e. http://localhost/api.

Run the app via yarn start