This repository holds an example backend for the ingestion API Safeplaces API specification.
Safeplaces is a toolkit for public health, built on top of data shared by users of Private Kit.
Safeplaces Frontend is an example client for these backends.
The project is still under development and will reach a Minimum Viable Product (MVP) stage soon.
Note: There can be breaking changes to the developing code until the MVP is released.
Note:
- The installation assumes you have already installed Postgres DB in your local environment listening for connections at port 5432.
- Your Postgres instance should listen to '*' instead of 'localhost' by setting the
listen_addressesparameter, this setting can be found in your pgconfig file.
Clone this repository
cd safeplaces-backend/expressjs
Steps to install NVM are documented in the nvm repository.
Install npm using nvm
nvm install 13.1.0
nvm use 13.1.0
npm install
Refer .env.template for environment variables to be exported to your environment.
- Create databases and users mentioned exported in your environment.
- Grant database user superuser privilege to the database to create POSTGIS extension and setup other tables. Reduce this privilege later to just create and modify tables or tuples in this database after you run the migration for the first time.
- Install PostGIS extension.
Install Knex globally
npm install knex -g
Run migrations
knex migrate:latest --env test
knex migrate:latest --env development
Seed the database
knex seed:run --env test
knex seed:run --env development
Install mocha globally.
npm install mocha -g
Run testing through mocha to see if unit tests pass
mocha
Note:
- The installation assumes you have already installed Postgres DB in your local environment listening for connections at port 5432.
- Your Postgres instance should listen to '*' instead of 'localhost' by setting the
listen_addressesparameter, this setting can be found in your pgconfig file. - Your
pg_hba.confshould have a rule added forhost all all <docker-subnet> md5. Replace<docker-subnet>with the actual CIDR for your docker installation's subnet. Note that172.18.0.0/16is usually the default.
Clone this repository
cd safeplaces-backend/expressjs
docker build -t safeplaces-backend-expressjs .
docker run --rm --name safeplaces-expressjs --env-file=.env -p 3000:3000 safeplaces-backend-expressjs
Note: sample env file can be found at .env.template`.
Using docker-compose will bring a postgres server along with the application container
Ensure to create application Environment variables file .env from .env.template
Ensure to create Postgres Environment variables file .database.env from .database.env.template
docker-compose build
docker-compose up
Run:
curl http://localhost:3000/health
Should respond with:
{
"message": "All Ok!"
}