Hattrick is a ReactJS + Redux + React-Router webapp tha be used as base for a community game where users can register, login, join to differents communities, post comments, etc.
The base of the game is that users would answers, everyday, 3 questions related to the community category, winning points and competing against the rest of the community users. An initial version of this webapp can be found in the client folder of this repo.
All of this can be made thanks a powerful REST API developed with Loopback. The API is prepared to work only with logged users, using authentication tokens. Users can also reset their passwords, join public and privates communities. An email system is implemented as well, and users will receive emails when they register or change their password.
The easiest way to deploy the WebApp and the API is using Docker:
docker-compose build;
docker-compose up;
It includes three different containers:
- hattrick: where the API will be deployed with PM2
- hattrick_db: where the database will be hosted
- hattrick_front: where the web-app will be deployed
By default:
- The REST API will be available in: http://localhost:10002/explorer
- The WebApp will be available in: http://localhost:10006/hattrick
Edit the start.config.json to set the following env vars:
- DB_HOST: database host (default: "hattrick_db")
- DB_NAME: database name (default: "hattrick")
- DB_PASSWORD: database (default: "hattrick")
- DB_USER: database user (default: "hattrick")
- APP_PORT: port where the REST API will be listening (default: 10002)
- APP_HOST: host/domain where the assets (images) will be located (default: "http://www.danigarcia-dev.com")
- CRYPTO_ALG: encryption algorithm used to encrypt user passwords (default: "aes-256-ctr")
- CRYPTO_PWD: encryption password for the encryption algorithm (default: "xxxxxxxxxx")
- EMAIL_USER: email address for nodemailer (default: "apphattrick@gmail.com")
- EMAIL_PWD: email password
- EMAIL_SERVICE: email service used for nodemailer (default: "Gmail")
Important: if you change the port where the REST API will be listening (APP_PORT), you must change it as well in the docker-compose.yml file.
For the database to be created when the hattrick_db container is started, we need to set up the env vars that the MySQL container will need. These var are defined in the mysql-environment.yml file:
- MYSQL_ROOT_PASSWORD: mysql root password
- MYSQL_USER: database name (default: "hattrick")
- MYSQL_PASSWORD: database password (default: "hattrick")
- MYSQL_DATABASE: database user (default: "hattrick")
When the container is started, the hattrick database will be created, as well a user with granted privileges. This database, user and password are the same that must be used in the REST API configuration.
Note: for those endpoints that need authentication, you must set the access token (given when login is done) in REST API explorer page in the text input you can find on the top-right corner.
POST
usersPOST
users/loginPOST
users/logoutPOST
users/resetPasswordGET
users/{id}PUT
users/{id}
POST
categoriesPUT
categories/{id}GET
categories/{id}POST
categories/{id}/questionsPUT
categories/{id}/questionsGET
categories/{id}/questions
Rest of the API endpoints are very similar in its behaviour to the ones explained previously.
So, I'm not going to repeat my self. Why don't you give it a try??!! =)
- Add roles for the users (PLAYER, ADMIN, etc.) and ACLs to the differente endponints depending on those roles. For example questions and categories should be only created by admins.