The new TripleA dice server re-written in JavaScript.
In order to be able to run the server you need to have a couple of things installed on your system:
node.js
>= 10yarn
postgres
>= 10
After those are installed on your system you can follow the steps below to get yourself up and running.
The steps assume node and yarn are on the PATH
of your system, if that's not the case, you need to replace node
and yarn
with the fully-qualified path name to the executable.yarn install
, this will resolve all dependencies for you and install them in node_modules
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.config.json
which contains all information the server needs to start.{
"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"
}
}
port
: The port node.js will listen on. Required.database
: Details about the database connection. Required.
username
: Username to authenticate with the database. Default: postgres
.password
: Password to authenticate with the database. Defaults to an empty String.host
: Hostname to connect to the database. Default localhost
.port
: Port to connect to the database. Default 5432
.database
: Name of the database to use, this should be the database you created in the one-time setup. Default dicedb
.email
: Settings that are used by the EmailManager. Required.
smtp
: Nodemailer SMTP Configuration, this object will be passed directly to Nodemailer without any further processing. Check the Nodemailer Docs. If you need a service to test emails locally you can use Ethereal, a dummy email service that doesn't actually sends emails but simulates a fully-featured SMTP server.display
: Display settings how the server will refer to itself in emails.
sender
: The Entry for the From:
field in the email. The actual email should be the correct one, otherwise the emails will likely land in SPAM Folders. Required.server
: Settings that define how the server will refer to itself in E-Mails. Required.
protocol
: The protocol that should be used to connect to this server. Default http
.host
: The hostname that should be used to refer to this server, ideally a domain. Default localhost
.port
: The port that should be used to connect to this server, if used behind a reverse-proxy this should be the public port. Default: 7654
.baseurl
: In case your server is in a non-root installation, set this to the folder name. (Example yourserver.com/dice
-> /dice
.) Defaults to an empty String.keys
:
private
: Path to the private key used to sign dice rolls. Required.public
: Path to the public key used to sign dice rolls. Required.In order to start the server run
node dice-server.js
It can be terminated using SIGTERM
, i.e. Ctrl+C
.
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.
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.
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"]
}
/api/roll
:
max
Integer. Specifies the highest outcome for each roll, must be <= 100.times
Integer. Specifies how many dice should be rolled, must be <= 100.email1
String. The first email to send the notification email to. This email needs to be registered.email2
String. The second email to send the notification to. This email needs to be registered.times
random numbers with a value in [1, max]
.dice
Integer Array: An array of the rolled dice.date
Integer: The current UNIX timestamp with millisecond precision. Taken into account for the signature so the signature can't be reused in the future.signature
: The base64-encoded signature verifying the integrity of the rolled dice./api/verify/:token
:
:token
Parameter:
{ "dice": [1, 2, 3], "date": 121332, "signature": "base64encodedsignature" }
.dice
Integer Array: An array of the dice rolls to be verified.date
Integer: A Unix Timestamp of the exact millisecond the original request was made. Important for the signature, and could potentially be used to check if this signature was made with a legacy certificate.signature
String: A base64-encoded RSA signature that can be verified by the server.valid
: A Boolean indicating if the integrity could be confirmed./register
:
email
String: The email a confirmation email will be sent to./register/:token
:
:token
Parameter:
email
String: The email to compare the token with./unregister
email
String: The email to remove from the database.
The Frontend is being served using templates and the liquid format. The same template engine is used for emails as well. Basically all pages consist of a classic HTML form that gets replaced with a responsive AJAX system if JavaScript is available.
/
:
/verify
:
token
String: The token to pass to the /api/verify
endpoint./register
:
email
String: The email to confirm the registration for.token
String: The token to pass to the /api/register/:token
endpoint./unregister
email
String, optional: The email to remove from the database, used to pre-fill the form.