- Node 12.14.x
- Postgres 9.5+
- Yarn
- Docker (for development work)
To set the Node version as specified above:
$ brew install nvm
$ nvm use
See this tutorial for details and instructions for installing PostgreSQL on your operating system
Scoreboard depends on three external services/APIs for statistics and functionality:
- OSMesa is a toolkit for processing large amounts of OSM vector data and turning them into stats (e.g: km of road added by user by country)
- Scoreboard pulls campaigns from the Tasking Manager and uses the campaign hashtags to pull campaign specific aggregations from OSMesa
- OSM Teams is a service that allows Scoreboard users to create teams and assign campaigns to a team.
Create a .env
file by copying the .env.sample
file and filling in the
required values. The sample file has comments above each possible environment
variable.
$ yarn
$ docker-compose up # wait for scoreboard_wait-for-db-ready_1
This command will create and run the database on port 5433
. The database files are stored under .tmp
folder.
If you are running the command for the first time, you should wait until the databases are created. This can take a few minutes.
To start with a new database with no data, stop the command, remove the .tmp
folder and run the command again.
Set up the database schema by running:
$ yarn migrate
You can rollback migrations with yarn rollback
.
For the frontend and the API to work, you must have the data loaded on the local database.
To generate fake user and campaign data run:
$ yarn seed
To be able to develop admin pages you'll need to have an admin user. Make your user an admin by running:
./api/bin/scoreboard create-admin-user --username {your osm username}
If you were already logged in, log out and log back in, then you'll see an "admin" link in the menu in the top right.
Known issue: before running create-admin-user
for username, you first have to login to the web app with that username first.
It could be useful to give some edits to your user in development.
You can run:
./api/bin/scoreboard create-edits --osm-id {your osm id}
This will select some random changesets from the OSMesa edits and assign them to your osm id
This command will start both the frontend and the api together, with livereloading for both the front end and api
$ yarn dev
This command will start both the frontend and the api together, with a static version of the api $ yarn dev-static
Tests for the API endpoints and related code are stored in api/tests/ and UI tests are stored in tests/. To run both:
$ yarn test
Test the UI and API separately using yarn test-ui
and yarn test-api
.
Lint the code using:
$ yarn lint
You can automatically fix some lint errors using yarn lintfix
.
If you make changes to the API documentation make sure to update the README for the API which is auto-generated from the swagger YAML by running:
$ yarn docs
In OSM-teams, choose "Connect a new app". For the callback URL use the path
/auth/teams/accept
For example in development, Scoreboard runs on localhost:8181, so the
callback URL would be https://localhost:8181/auth/teams/accept
.
The client id and client secret should be saved to your Scoreboard .env
file.
Scoreboard will work with a single organization at the moment. In osm-teams, record your organization's
ID from the API and use the environment variable OSM_TEAMS_ORG_ID
to have scoreboard read and write
to the organization's teams.
If you are setting up local development for the first time, you may need to create an organization. There is currently no way to do this via the osm teams interfaces. Instead you can use the swagger UI to make the requests.
- check to see what organizations exist on your local osm-teams
- if there is none, create an organization (the id can be anything, but should match
OSM_TEAMS_ORG_ID
in your scoreboard.env
) - run
yarn seed
- clear your cache and login
The Administrator Settings are found in the Admin user's dashboard, or via the Admin entry in the User menu.
- Tasking Managers: Currently HOT Tasking Manager (TM2 - TM3) is supported.
- Setup Badges
- Manage Users
- App Settings: OSMesa integration settings
A pg_dump of osm-fabricator is used to mock the osmesa db when developing locally.
To update the osmesa db, first develop on osm-fabricator, then pg_dump it into docker-context/osmesa-mock/init.sql
.
See scoreboard's docker-compose.yml
for more details.
See api/README
To use scoreboard in production follow these steps:
- Make sure you have all the requirements.
- Install dependencies:
yarn
- Setup a production Postgres database
- Create the database by running these commands.
- Setup an
.env
file with correct values -> example.- make sure to set
NODE_ENV=production
in your.env
file
- make sure to set
- Run the migrations:
npm run migrate
- Add initial data to the database (skip if the database already has data)
npm run seed
- [OPTIONAL] Preload list of users
npm run users
- Populate stats:
npm run clocks
- [OPTIONAL] Assign admin users by running
./api/bin/scoreboard create-admin-user --osm-id {your-id}
- Note:
- Build:
npm run build
- Launch the server:
node server.js