Skip to content

Developer setup

Nathanaël edited this page Apr 19, 2021 · 40 revisions

Requirements

  • NodeJS (at least > v14)
  • MariaDB > v10.4
  • Git
  • Bash (or equivalent) to run the git hooks
  • A .env file with all the mandatory variables

Git hooks

We use some githooks to automate some tasks: format & lint code, update API documentation. Install them in your local repository with ./githooks/setup-hooks.sh (you can remove the created simlinks in your local repository if they annoy you). This requires to have the API docs repository cloned next to the main repository

$ ls -l MAIN_FOLDER
apothiquiz/
apothiquiz-api-docs/
wiki/
[... other files]

Create the database

# Create the apothiquiz user
CREATE USER 'apothiquizUser'@'localhost' IDENTIFIED BY 'p@ssword';

# Create the database
CREATE DATABASE apothiquizDb;
GRANT ALL PRIVILEGES ON apothiquizDb.* TO 'apothiquizUser'@'localhost';

-- Create the database for tests
CREATE DATABASE apothiquizTestDb;
GRANT ALL PRIVILEGES ON apothiquizTestDb.* TO 'apothiquizUser'@'localhost';

Insert test data in the database with the scripts in ./server/test/required_data/*.sql. Note that the database is emptyied after each test (it's why we use a different database for them).

Set the .env

The .env is a file containing all the environment variables required to run the server. It must be in the server/ directory. See below the template of the required .env file

# Database
DB_HOST=localhost
DB_USER=apothiquizUser
DB_PASSWORD=p@ssword
DB_DATABASE=apothiquizDb
DB_DATABASE_TEST=apothiquizTestDb

# Token private keys : for production, these keys must be a random hash !
# https://www.random.org/passwords/?num=5&len=24&format=html&rnd=new or `openssl rand -base64 32`
ACCESS_TOKEN_KEY=ACCESS_TMP 
REFRESH_TOKEN_KEY=REFRESH_TMP

Install Node.js dependencies

Run npm install (or npm i) in both server/ and client/ directories to install all dependencies with npm.

Run development server

You can use nodemon to auto-reload the server on changes. For the client, use npm run start to start the Create-React-App script, which is watching the changes by default

Load testing

Use npm run test:generate-data <number-of-users> <number-of-duels> to generate fake data in your dev database. It take approximately 10 minutes for 300 users and 3000 rounds (the default settings).

Clone this wiki locally