evzpav / knight-moves

It is a small game that highlights chessboard cells corresponding to the possible positions that the piece knight on the chess can stay after playing 2 times consecutively.

Home Page:https://knight-moves-evzpav.herokuapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Knight Moves

It is a small game that highlights chessboard cells corresponding to the possible positions that the piece knight on the chess can stay after playing 2 times consecutively.

It consists of a backend server in NodeJs with Express and a frontend client in ReactJs.

  • Client: React
  • Server: NodeJs (Typescript)

Instructions to run

Below you can find 2 ways to run this project.

Method 1 (recommended):

Pre-requisites:

# Clone repository

# Start mongo on docker (optional)
make mongo

# Build front and run server on docker
make run-docker

# Server will be running on http://localhost:3000

Method 2

Pre-requisites:

# Clone repository

# Run mongo at port 27018 (optional)

# Download dependencies for client and server
sudo npm i -g typescript
sudo npm i -g ts-node
make install

# Generate build files for client (./build folder)
make build-front

# Run server (it will also serve the ./build folder)
make run

# Server will be running on http://localhost:3000

Unit Tests

The business logic inside server/services is tested within ./tests folder using Mocha and Chai:

make test

Lint

Run linters on server and client

make lint

Audits

Run dependencies audit

make audit

REST API Documentation

All available REST API documentation exposed by the project was documented using the OpenAPI standard.

To view this documentation locally use the following command:

make run-swagger

Deployment to Heroku or Dokku

To deploy this project to Heroku as one app only, it the server will be serving the static content of the ./client/build folder. For that, the way I figured to make it work it is to commit the ./client/build folder to git.

# Build front needs to be done locally
make build-front

# And on .gitignore ./client/build folder needs to be removed
# So the static files are commited when sent to heroku/dokku

After this the normal procedure for a Heroku app deploy can be done.

PS.: A better way would be to run server as a separate Heroku app and another app with NGINX image to run the web server for the static files of the frontend. However it would need to git repositories for it.

Further details:

After clicking the square in the chessboard, a GET request passing the position in algebric format (e.g.:A8, D5, H1) as param in the URL. The string of the position will be checked in the server according to a regex, and if it passes then the calculation of the possible knight moves for 2 turns in advance are made and the result with an array with all the positions in algebric format is sent to the client that highlights the corresponding cells that are already mapped.

About

It is a small game that highlights chessboard cells corresponding to the possible positions that the piece knight on the chess can stay after playing 2 times consecutively.

https://knight-moves-evzpav.herokuapp.com/


Languages

Language:CSS 31.0%Language:TypeScript 30.2%Language:JavaScript 26.2%Language:HTML 6.8%Language:Makefile 3.7%Language:Dockerfile 2.2%