
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
Peddlers of Ketran
This project consists of both the front-end and back-end game API server.
The front-end is launched in development mode via 'npm start'. In production, you build it via 'npm build' and deploy the public front-end. When you run the development mode, the default port it will bind to is 8931.
The back-end is launched out of the 'server' directory via 'npm start' and will bind to the default port 8930.
If you change the default port of the REST API server, you will need to change client/package.json's "proxy" value to reflect the new port change.
NOTE:
Board.js currently hard codes assetsPath and gamesPath to be absolute as the dynamic router and resource / asset loading isn't working correctly.
Building
Native
Prerequisites
sudo apt-get install -y nodejs npm python
sudo -E npm install --global npm@latest
In container
Architecture
skinparam componentStyle rectangle
component "Server" as server
component "Resources" as res
component "Client" as client
component "Game" as game
component "Player" as player
package "Game" as game {
component Players as players
}
server <-> resource : serves to client
client <-> server
player <-> client
players -r-> player
server -> game
Ketr.Ketran REST API
POST /api/v1/game
Request
{}
Response
{
gameId: id
gameState: {
tiles: []
}
}
Configuring / installing
Build
git clone git.ketrenos.com:jketreno/peddlers-of-ketran.git
npm install
cd server
npm install
npm start &
cd ..
npm start
Install
export BASEPATH=${PWD}
# Ensure sudo has password ready
sudo -l
envsubst BASEPATH < install/ketr.ketran | sudo tee /etc/logrotate.d/ketr.ketran
envsubst BASEPATH < install/ketr.ketran.service | sudo tee /etc/systemd/system/ketr.ketran.service
sudo systemctl daemon-reload
Install the following into your nginx server configuration:
location /ketr.ketran {
alias ${BASEPATH};
}
location ~ /ketr.ketran/api/.* {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass_header Set-Cookie;
proxy_pass_header P3P;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://localhost:8930;
}
Add security tokens in ketr.ketran/config/local.json:
cat << EOF > config/local.json
{
"tokens": [ {
"$(whoami)": "$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;)"
} ]
}
EOF
Launch
sudo systemctl start ketr.ketran
To test
New game
curl -k -s -X POST http://localhost:8930/ketr.ketran/api/v1/games/
Game status
curl -k -s -X GET http://localhost:8930/ketr.ketran/api/v1/games/:id