API server providing access to licence and user data
To run a local instance:
npm run dev
@asl/service/api
provides the common api boilerplate - body-parsing, auth etc.@asl/schema
provides models for interacting with database objects
The service can be configured for local development by setting environment variables in a .env
file.
The following environment variables are required:
WORKFLOW_SERVICE
- the url of theasl-workflow
instanceSEARCH_SERVICE
- the url of theasl-public-search
instancePERMISSIONS_SERVICE
- the url of theasl-permissions
instanceDATABASE_NAME
- the name of your postgres databaseKEYCLOAK_REALM
- the keycloak realm used for authenticationKEYCLOAK_URL
- the url of the keycloak serverKEYCLOAK_CLIENT
- the client name used to authenticate with keycloakKEYCLOAK_SECRET
- the secret used to authenticate with the keycloak clientKEYCLOAK_USERNAME
- administrator username to authenticate with the keycloak clientKEYCLOAK_PASSWORD
- administrator password used to authenticate with the keycloak client
The following environment variables can be optionally defined:
PORT
- port that the service will listen on - default8080
DATABASE_HOST
- hostname of the postgres instance - defaultlocalhost
DATABASE_PORT
- port of the postgres instance - default5432
DATABASE_USERNAME
- username of the postgres instance - defaultundefined
DATABASE_PASSWORD
- password of the postgres instance - defaultundefined
DATABASE_POOL_SIZE
- maximum size of the postgres connection pool - default5
REDIS_HOST
- redis instance used to store rate limit data - defaultlocalhost
REDIS_PORT
- redis instance used to store rate limit data - default6379
REDIS_PASSWORD
- redis instance used to store rate limit data - defaultundefined
RATE_LIMIT_TOTAL
- maximum requests per hour allowable per-user - default1000
BODY_SIZE_LIMIT
- maximum body size for requests - default50mb
asl
- establishment facing uiasl-inspector-ui
- internal facing ui.
The following services must be available in order to run:
asl-permissions
- permissions microserviceasl-workflow
- api providing workflow management on change requestspostgres
- to store licence data
Scripts for setting up a local database with dev data are available in the asl-schema
project. First clone that repo and install the dependencies. Then run the following commands in the schema project directory:
To setup the inital table schemas:
npm run migrate
To seed the database with a development dataset:
npm run seed
Note: these scripts will require the database described by DATABASE_NAME
to be created before they can run. If running against services run with asl-conductor
then this will be done automatically.
Project contains a set of unit tests driven by supertest
to make mock requests to the API. To run these:
npm test
The tests are run against a real database instance seeded with data found in ./test/data/default.js. This is regenerated before each test.
The configuration for the database used for the test runner can be set with the following environment variables (note that these are different from the variables used to configure a running instance to avoid conflicts with "real" data):
POSTGRES_DB
- defaultasl-test
POSTGRES_USER
- defaultundefined
POSTGRES_HOST
- defaultlocalhost
POSTGRES_PASSWORD
- defaultundefined
Note: you may need to create the database asl-test
locally before running tests for the first time. If running against services run with asl-conductor
then this will be done automatically.
By default when running tests the user will have full permissions. To define a custom permissions function to use in a test, run the the following code before making an API call:
this.api.setUser({ can: (task, params) => <Promise> });