A small chess project based on the chess backend developed here.
It conists of a flask backend which provides a REST-like API and passes this on to the mentioned Chess Online chess implementation and also of a React frontend.
Short version (Linux):
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cd react-front-end
npm install
npm run build
cd ..
./main.py
Then there hsould be a usable front end.
If you want to test the game visit the test page in another browser or in a private window.
You should be able to create a lot of games and access them trough the /<id>
slug. You can also visit other players using this.
As the flask server provides a REST-like API it should be possible to access the server from any device.
The API itself works in the following way: In the /api/ route (home or index) are all indices listed. The client just has to GET from there to get all existing games. If POST is used at the home route a new game is created and the index is returned. The client has then the chance to view the created game at /api// So if there is already a game listed it is possible to view it by adding the id to the URL. IMPORTANT: Accessing this route is only possible by adding a randomly generated key. This can be anything. It should be saved as a cookie or at least in the browser as this key will be used to identify the currently active player. If the browser is closed while playing the game and the key is forgotten there is no way to return the game and play as the same player.
So a few examples:
GET /api/
[{"id": 0}, {"id": 1}]
POST /api/
{"id": 2}
GET /api/2/ data={ "key": "unique_player_key" }
{
"board": "RNBKQBNRPPPP...",
"role": "white"
}
PUT /2/ data={ "move": "a2a3", "key": "unique_player_key" }
{
"board": "R...",
"valid": true,
"message": "PASSED",
"player": "black"
}
The react front end automatically creates a unique key as a cookie and saves it which is why you are recognized as one player even if you save the browser.
If you want to push it to e.g. Heroku remember to add python and nodejs as buildpacks. So heroku buildpacks:add --index 1 heroku/nodejs
should do the trick.