There are 3 modules in this codebase:
- Server (located in root directory): the codebase which provides the API and serves static files.
- App (located in
/app
): the web-based interface for the app. - Admin (located in
/admin
): a web-based interface for the admin panel.
Before you begin, you should fork this repository to your own Github account so that you have your own copy of the code.
The server is a node.js web application. This provides the backend API and also serves up the static files for the App and Admin modules.
The server is configured such that it can be easily deployed to Heroku. However, you may host using whatever service you like.
You will need to have mongodb installed locally. Run the following commands from the root directory of this repository.
- Configure environment variables:
cp .env.example.dev .env
and then edit this.env
file to suit your preferences. See the list of environment variables below. - Copy environment variables from above automatically to the react apps:
npm run build-env
- Setup:
npm install
- Start the server:
npm start
. This will host the server onlocalhost:8000
. - Start the app (separate terminal window):
cd app && npm start
. This will host the app onlocalhost:3000
. - Start the admin (separate terminal window):
cd admin && npm start
. This will host the admin onlocalhost:3001
. - Test:
npm test
This can be easily deployed to Heroku as follows:
- Create a new Heroku app
- Configure the environment variables (config vars) in the Heroku app. See description of environment variables below, as well as the example production configuration in
.env.example.prod
. - Connect the Heroku app to your forked Github repository. This will allow you to deploy from Github. You can even enable automatic deploys whenever new code is pushed. Heroku will automatically build the
app
andadmin
modules each time the server is deployed.
NODE_ENV
: Indicates whether adevelopment
orproduction
environmentAPP_NAME
: Whatever your app will be called.APP_DOMAIN
: The domain where your app will be hosted.ADMIN_DOMAIN
: The domain where the admin panel will be hosted (should be the same asAPP_DOMAIN
in production)SERVER_DOMAIN
: The domain where the server will be hosted (should be the same asAPP_DOMAIN
in production)ABOUT_URL
: A web address where people can learn more about your projectAPP_THEME
: Specify eitherdark
orlight
depending on how you want your app to look.QUARANTINE_DAYS
: How many days after contact to alert people of potential exposure, i.e. number of days to quarantine (for example, 14). Should be set according to public health guidelines.CONTACT_WINDOW_HOURS_BEFORE
: How many hours before an exposed checkpoint occurred for others that scanned the same checkpoint to be considered a contactCONTACT_WINDOW_HOURS_AFTER
: How many hours after an exposed checkpoint occurred for others that scanned the same checkpoint to be considered a contactMONGODB_URI
: The mongodb database URL. (This will be automatically set in Heroku if you use the mLab addon.)SESSION_KEY
: A secret key which encrypts user sessions for the admin panel. This can be anything but it should be random and secret.REDIRECT_HTTPS
: Whether to automatically redirect http to https; should betrue
in production.CHECKPOINT_KEY_LENGTH
: How many characters should be in the checkpoint key; set this to16
unless you have some reason to change it.ADMIN_REGISTRATION_URL
: An optional environment variable. It is intended to provide a link to a Google form where you can collect requests for admin access. You may create a form similar to the following: https://forms.gle/J38BLRpFtRFT846Z8. When this environment variable is set, the link will be provided on the admin login page.SENDGRID_API_KEY
: Used to send emails to admins for account management. You can create a free account on Sendgrid for local development and testing.ADMIN_EMAIL_FROM
: The "from" address used for emails sent to admins for account management.LOCIZE_PRODUCT_ID
: If you would like to use the Locize service to manage translations, you can provide your Locize product ID here, and the app will automatically use those translations.
The app module is a React web application. This provides the source code for the main app interface.
The server will render the built app code at the root url. If you make changes to the source code, they will not be visible until you run npm run build
from the /app
directory.
The app module will also be built when you run npm install
from the server (root directory).
The admin module is also a React web application. This provides the source code for the admin panel interface. This is the system which doctors (or other authorized personnel) will use to upload QR code history files on behalf of COVID-positive patients.
The server will render the built admin code at the root url. If you make changes to the source code, they will not be visible until you run npm run build
from the /admin
directory.
The admin module will also be built when you run npm install
from the server (root directory).
The admin dashboard uses Sendgrid for account management (sending users their initial password, and password resets). You can create a free account, which will allow you to send 40,000 emails for the first 30 days, then 100/day after that.
- Create your free Sendgrid account
- In Sendgrid, verify the "from" email address you will be using (needs to match the "from" email address in step 4). Instructions here.
- Copy your API key from Sendgrid (It should start with the letters
SG
). Set the environment variableSENDGRID_API_KEY
to this value. - Set the environment variable
ADMIN_EMAIL_FROM
to the email address to use as the "from" email address for automated account management emails (e.g. password reset emails). Emails will appear as having been sent from this address in users' email inboxes.
You can create your first admin user by running the following from the root directory of this project: npm run create-user
. This will prompt you for your mongodb url, desired username, and password. Be sure to use the appropriate mongodb url depending on whether you are trying to create a user in your production database or your local database. Also, if you're using Heroku and mLab, make sure to include &retryWrites=false
at the end of the mongodb url.
Once this user is created, you can log in to the admin panel using these credentials, and create other user accounts from within that interface.
Data that is older than the period of time set by QUARANTINE_DAYS
is no longer needed or useful and should be deleted. This can be done by running node clean-database.js
from the root of the project. To continually clean the database, this should be scheduled as a job. On Heroku, this can be easily done using the Heroku Scheduler addon. Just create a job for the command node clean-database.js
and have it execute either every hour or every day, depending on how often you want the cleaning to occur.