triplea-game / dice-server-js

The new TripleA dice server powered by Node.js
GNU Affero General Public License v3.0
6 stars 6 forks source link

Travis

dice-server-js

The new TripleA dice server re-written in JavaScript.

Setup

Prequisites

In order to be able to run the server you need to have a couple of things installed on your system:

One-Time-Setup

  1. Clone this Repository in a directory of your choice.
  2. Open a terminal and navigate to the newly checked out directory.
  3. Run yarn install, this will resolve all dependencies for you and install them in node_modules
    • Generate an RSA key-pair. If you have installed openssl and it's on your PATH, you can simply run yarn generate-keypair, which will create the files privkey.pem and pubkey.pem in the current directory.
    • On production systems you should move them into a "save directory" and (at least on UNIX-like systems) restrict read access of the private key to the user that's going to run the server and root.
    • Create a file config.json which contains all information the server needs to start.
    • Alternatively those configuration options can be passed via CLI directly or as environment variables. Check the nconf docs for more information.
    • The config files' layout will be explained below.
  4. Create a database in Postgres to be used by the server.

config.json

{
  "port": 7654,
  "database": {
    "username": "postgres",
    "password": "",
    "host": "localhost",
    "port": 5432,
    "database": "dicedb"
  },
  "email": {
    "smtp": {
      "host": "smtp.provider.com",
      "port": 587,
      "auth": {
        "user": "your.email@provider.com",
        "pass": "super secret password no one will ever guess"
      }
    },
    "display": {
      "sender": "\"Display Name\" <your.email@provider.com>",
      "server": {
        "protocol": "http",
        "host": "localhost",
        "port": 7654,
        "baseurl": ""
      }
    }
  },
  "keys": {
    "private": "./privkey.pem",
    "public": "./pubkey.pem"
  }
}

Starting

In order to start the server run node dice-server.js It can be terminated using SIGTERM, i.e. Ctrl+C.

Testing

In order to run all local tests and eslint, you can simply run yarn test This is also the command that will be executed by Travis.

Routes

The dice server is divided into 2 seperate routers. The REST Service handles all calls under /api. All other requests are handled by the frontend which basically wraps the API calls with a nice UI.

API

All of the requests return JSON in the same format. When successful:

{
  "status": "OK",
  "result": {
    "some info": "some value",
    "other info": true
  }
}

result is optional, if it's not present this simply means that the server has no additional information for this request. On Error:

{
  "status": "Error",
  "errors": ["List", "of", "error", "messages"]
}

Routes