This is Opal's backend listener that facilitates communication between the user applications and the Opal PIE (typically running within a hospital network that cannot be accessed from the outside) via Firebase.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
These are the requirements to run the listener locally.
- Docker
- Have the new opal-admin and legacy databases running.
- Have your own Firebase project set up and the Firebase admin key file saved.
Copy your Firebase admin key file into the src/config/ directory.
The content of this directory is ignored from version control.
Copy and rename .env.sample to .env.
Then, fill out the fields according to your local installation (most importantly, the Firebase database URL copied from your Firebase project's settings, and the two backend auth tokens).
Note that the backend auth tokens will have been generated for you when initializing your test data in the backend project.
Communication with the backend needs to be authenticated with a REST API token. It is assumed that at this point you already have the backend set up with initial data which generated these.
- The
FIREBASE_DATABASE_URLcan be found in the exported app configuration from Firebase - The
FIREBASE_ADMIN_KEY_PATHdefaults to/app/src/config/firebase-admin-key.jsoninside the container (i.e.,src/config/firebase-admin-key.jsonin your project) - Notice that the host names are
host.docker.internaland NOTlocalhost. This is required for a container to call a localhost service on the host system. DATA_CACHE_TIME_TO_LIVE_MINUTESrepresents the length of time in minutes the listener will store a given user's salt and secret keys when requesting encryption values
The project contains Dockerfile and docker-compose.yml files to build an image and run the app as a container, either for a production-like setup or development.
To build the Docker image and run the container, running the following command at the root of the project
docker compose upMore information about Docker compose can be found on the Docker Compose page.
Settings are available in this project to allow the listener to use encrypted connections to the databases, and when making external requests. Enabling SSL is optional. Note that the instructions below are for a local setup. On a server, certificate files may be stored in different locations.
- Copy your CA public key file (usually called
ca.pem; generated when setting up SSL in db-docker) to thecertsfolder. - In the
.envfile under--- SSL Configurations ---, enable SSL and provide the path to this file. - Restart your Docker container via
docker compose upwhich forces the container to be recreated.
To ensure that your setup was successful, make sure the listener launches successfully, and that the database queries
print Grabbed SQL connection ... with SSL enabled to the logger, and complete successfully.
If external HTTP requests are intercepted by a proxy (e.g., via deep packet inspection) HTTPS requests might fail if a custom/internal certificate authority is used.
In this case, provide a certificate bundle that includes this certificate, make it available inside the container, and set the NODE_EXTRA_CA_CERTS environment variable.
This project uses ESLint to statically analyze its source code. It has been configured to only analyze new files in the
context of strangler fig (i.e. to ignore legacy files in the listener and legacy-registration folders).
For a full list of the ESLint plugins and rules configured in this project, see eslint.config.js.
Follow the steps below to enable ESLint in your IDE.
To enable ESLint in VSCode, install the recommended plugin ESLint by Microsoft.
- Go to
File > Settings/Preferences > Languages & Frameworks > JavaScript > Code Quality Tools > ESLint. - Select
Automatic ESLint configuration.
To generate and view the project documentation, follow the steps below.
- Generate the documentation using
npm run docs. - Using your IDE, right-click on the file
docs/generated/index.htmland select the option to open it in a browser.
For help on creating new documentation pages, refer to {@tutorial creating-documentation}.
Unit tests for this repository are run using the Mocha test framework.
Tests are required for any new code written in the src directory (or any of its subdirectories), and test files should have a name in the format *.test.*.
In other (legacy) parts of the project, tests are not necessarily required.
However, they can still be created to improve coverage or to test new code when the legacy part of the system is modified.
To run the tests:
npm testIt is possible to simulate a request from the Opal app, for testing, by using the simulate request script. There are two way to do so:
Using the npm script simulateRequest which will use the default request data specified in the file src/test/simulate-request/mock-request.js
or
Instantiate the SimulateRequest class and pass the mock request as an argument new SimulateRequest(MockRequestData);.
Note that the mock request data need to have the same structure as src/test/simulate-request/mock-request.js.
You also need to specify the correct firebase UserID that is linked to your local development setup and database.
- Node - The server-side library used
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the AGPL v3.0 License - see the LICENSE file for details