Task of RPSSL service for Billups. Main focus is on backend written in Go, frontend is just for fun. Thus only main backend task was properly structured and covered with tests. Frontend and some optional backend tasks are not covered with tests and may present bad development practices.
Optional tasks were done as well:
- GUI uses Vue 3 (see below for details)
- Scoreboards are implemented for local and global scores
- Every scoreboard may be reset
- P2P is implemented using WebSockets and with a separate scoreboard per game
- Multiple users can easily and separately play on the server
- Dockerfile-s are provided, as well as full docker-compose build
- Some fun things were added with the help of new technologies (see live version)
Main task was:
This server is for playing game of Rock, Paper, Scissors, Lizard, Spock. The server can use an external supply of random numbers (though this might slow down some functions). To use external provider, please provide necessary arguments to the executable. Alternatively you can provide them through environment variable for Docker.
Some features are not covered with tests for speedup purposes, but main task functionality — three required endpoints and use of external RNG — are tested.
First change directory to ./backend
.
To build and run the code, first install the dependencies listed in go.mod
then build with go build -o rpssl ./cmd/main.go
and run the created executable.
You can provide arguments:
- Listen to a different interface:port, for example: —
rpssl --addr 185.34.1.4:342
. Default is:8080
. - Use external rng provider at http://youraddress.com/provider, —
rpssl --rng http://youraddress.com/provider
. Default — internal provider based on libraryrand
. - Set log level —
rpssl --log-level debug
. Default —info
. - Set log type to json or text —
rpssl --log-type json
. Default —text
.
You can combine these parameters as needed.
Alternatively you can:
First change directory to ./backend
.
docker build -t rpssl4bu .
docker run -e EXTERNAL_RNG=<rng_provider_address> rpssl4bu
or just docker run rpssl4bu
to use internal RNG
Port 8080 is exposed by default.
To experience the full powers of the backend, you need to use specially crafted...
This frontend, being based on Vue.JS 3, is created as solo component because the frontend isn't the main part of the task. No testing was added either.
The frontend can be bound to different backend servers, though some features will stop working for non-authentic backend servers.
If you want to run it together with the backend in docker-compose, nothing
needs to be done — just use the provided docker-compose.yml
file.
If you want to run against a different backend server, you can:
- Fix the value of
backendServer
property in./frontend_vue/src/App.vue
- Change backend server on the go directly from the GUI
- Set up
VUE_APP_BACKEND_URL
in.env
before building Vue application - Set up the
BACKEND_URL
environment variable when building a Docker container
First change directory to ./frontend_vue
.
Ensure you have the latest Node.JS and NPM installed, then:
echo VUE_APP_BACKEND_URL=http://your.backend/server/>.env
npm install
npm run serve
or alternatively
npm run build
As another way to run, you can use
First change directory to ./frontend_vue
.
docker build -t rpssl4bu_vue .
docker run rpssl4bu_vue
There are two environment variables that you could set up for the build of the container:
FRONTEND_LOCATION
— the prefix at which the Vue application will be located, must be set if your GUI will not be located in the root server directoryBACKEND_URL
— address of the backend service endpoints root
Port 80 is exposed by default.
But probably you'd like to run
There's a docker-compose.yml
provided to run both backend and frontend at
the same time, already bundled up. To run both together, just run
docker-compose build
and docker-compose up
.
Frontend will be mounted in /
and backend will be mounted in /backend/
of your server.
Under the hood it will use a couple of NGINX servers, the primary one is set up
in ./configs/nginx/conf.d/main.conf
.
Port 80 is exposed.