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
-
Set environment variables
Ensurecp packages/api/.env.example packages/api/.env
API_BASE_PATH=""
to allow running standalone (as opposed to part of full stack) -
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 -
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
-
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
--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
-
Configure .env variables as per
packages\server\README.md
EnsureAPI_BASE_PATH="/api"
to allow running as part of full stack -
Build api
yarn workspace api docker:build
-
run server stack
NOTE - if users need to be configured then this can be done using the stack PGAdmin available atyarn workspace server start
localhost:5050
with a connection host namedb
(instead of localhost) -
Interact with app Update the
API_ENDPOINT
specified insrc\app\shared\services\server\interceptors.ts
to target docker stack in development, i.e.http://localhost/api
.
Run the app via yarn start