Giter Site home page Giter Site logo

ldeluigi / higher-lower-pwned Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 65.01 MB

A game website where you guess the most popular password to win! You can play solo, 1v1 or in a battle royale!

Home Page: https://pwnedgame.azurewebsites.net

Dockerfile 0.25% JavaScript 34.31% TypeScript 49.34% Shell 0.16% HTML 8.62% SCSS 7.31%
angular docker nginx nodemon passwords game anti-cheating statistics

higher-lower-pwned's Introduction

Node.js CI Angular CI

The Pwned Game

This project is a web game where you guess which password is the most popular between two shown on screen.

Technologies

Note: Versions listed here refer to the one used to build the project, but it should work with the most recent minor version of the same major.

Needed on the host

Used in the project

  • Nginx
  • Nodemon
  • NodeJS
  • Socket.io
  • MongoDB
  • Express
  • Angular
  • Angular Material
  • Mongoose
  • ...

Development: server

Before starting

Please keep in mind that the server needs some enviroment variables to be defined inside an .env in the root folder, which could look like:

HOST_PORT=9000
JWT_SECRET=yummy
MONGO_DB_NAME=hlp-db
MONGO_DB_USERNAME=hlp
MONGO_DB_PASSWORD=hotdog
MONGO_DB_ROOT_PASSWORD=hotdogwithsauce
EMAIL_DEBUG=true

Explanation

  • The production server will be available at the port HOST_PORT, which is managed by Nginx. Nginx will serve static files and forward API/socket requests to the backend container
  • Database admin access is granted to user root (fixed) with password MONGO_DB_ROOT_PASSWORD, in the authentication db admin (fixed). Another user, MONGO_DB_USERNAME, will be used by the backend server to authenticate to the mongo container in order to have access to the db MONGO_DB_NAME, using password MONGO_DB_PASSWORD.
  • JWT_SECRET will be used to sign Json Web Tokens.
  • EMAIL_DEBUG, if set to true, will enable email debug mode, meaning that emails will be printed on console if a better way of sending them is not available.

Optional environment variables:

  • MAILER_EMAIL and MAILER_PASSWORD are the credentials to use a mail account to send emails. If both have values, nodemailer will use them to send emails.

Currently supported mail services:

Note: You can prevent uploading sensitive data inside the .env file with:
git update-index --assume-unchanged .env

Development mode

First you need to install server dependencies with npm install, run inside the server folder backend/js.
To develop a server, run the docker compose file for Development mode with:
docker compose -f docker-compose.dev.yml up -d from the root folder. Docker should create these containers:

  • mongo that manages the database
    • Data is saved in a named volume by docker hlp-mongo-db-data
    • Logs are saved inside /backend/mongo/data/log on the host machine
    • Mongo setup is stored in /backend/mongo/setup
  • hlp-backend-dev with the live version of the nodejs backend mapped with host source files, and updated in real-time by nodemon
    • Every file inside /backend/js is mapped inside the container, including node_modules
    • After an edit is detected by nodemon on the source files (.js, .json) index.js is restarted inside the container, so that changes are online as soon as possible
    • You can look at the container logs for errors or debugging, with docker logs --follow <backend-container-id>

Development: client

To develop the client, follow the instructions in the previous section. When you have the backend ready and listening on its port, you can use any frontend to communicate with it, directly from your local machine or host.

API Documentation

Available in the Wiki.

Developing the Angular Web App client

The client is developed and compiled on the host machine, so you need to run npm install in the frontend folder frontend/angular/hlp to download dependencies. If you want to contribute to the main client made with Angular you can write your code while ng serve provides a live version if it, automatically updated and compiled.

Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Update dependencies

In order to update the dependencies without accidentally changing the Angular major version, use ng update @angular/cli@^10 @angular/core@^10.

Manual tests

To test the angular client by hand usually you just need to run ng serve, but if you want to make the client available to every machine on your local network, making the angular host similar to a server, you need:

  1. To make sure that the backend port is mapped to an host public port and reachable from the local network;
  2. To set your machine IP address and backend port inside the environment.ts file;
  3. To run ng serve --host 0.0.0.0 --port <port> --disableHostCheck to serve the client on the specified port on your machine ip under your local network.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run ng e2e to execute the end-to-end tests via Protractor.

Production mode

To run the entire project in production mode just type docker compose up -d in the root folder of the repository. This is a simulation of a production environment on your local machine. On Windows, MongoDB /data/db folder can't be mounted on a volume shared with the host machine. To achieve persistency of data, either user docker native modules or an external database. In order to use an external MongoDB database configure it properly (see the configuration file of the project) and use the docker-compose.extdb.yml compose file, after having defined the environment variable MONGO_DB_URL.

Note: Only requests to /api or /socket path are forwarded to the server by Nginx.

Stopping containers

To properly stop running containers use docker compose [-f ...] down. To stop and clean volumes use docker compose [-f ...] down -v.
Note: Volumes left inside docker storage could fill up the space on the host machine!

higher-lower-pwned's People

Contributors

davideeva avatar dependabot[bot] avatar github-actions[bot] avatar ldeluigi avatar simonemagnani avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

higher-lower-pwned's Issues

CSS bug

image
With menu open, in mobile landscape mode, buttons become rectangular

Use oldPassword

Use oldPassword field in user password update.
/api/users/:id
PUT
Old input:

{
  password?: password,
  email?: email
}

New input:

{
  oldPassword?: password,
  password?: password,
  email?: email
}

Limits in user/userid/stats and user/userid/scores are wrong

Currently working on an app using this API.
Turns out that the "limit" parameter in user/userid/stats and user/userid/scores specified in the wiki are wrong.

For the first url, it works with a max limit of 30.
For the latter, a working max limit is 500.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.