summaryrefslogtreecommitdiff
path: root/public/docs/production.html
blob: abb0b7cf5d834e76806b1fe81efdaf01c27257f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!doctype html>
<title>Public Server</title>
<link rel="stylesheet" href="style.css">
<body>
<article>

<h1>
Running a public server
</h1>

<p>
To let other people connect to your server and play games, there are a few other things you will need to set up.

<h2>
Recovering from a crash
</h2>

<p>
Use <tt>nodemon</tt> to restart the server if it crashes.
This also restarts the server if the software is updated.

<pre>
nodemon server.js
</pre>

<h2>
Database &amp; Backups
</h2>

<p>
For best performance, you should turn on WAL mode on the database.

<pre>
sqlite3 db "pragma journal_mode = wal"
</pre>

<p>
You will want to backup your database periodically. This is easy to do with a single sqlite command.
Schedule the following command using cron or something similar, and make sure to copy the resulting
backup database to another machine!

<pre>
sqlite3 db "vacuum into strftime('backup-%Y%m%d-%H%M.db')"
</pre>

<h2>
Customize settings
</h2>

<p>
The server reads its settings from the .env file.

<pre>
NODE_ENV=production

SITE_NAME=Example
SITE_URL=https://example.com
SITE_IMPRINT="This website is operated by ..."

HTTP_HOST=localhost
HTTP_PORT=8080

# Enable mail notifications
MAIL_FROM=Example Notifications &lt;notifications@example.com&gt;
MAIL_HOST=localhost
MAIL_PORT=25

# Enable webhooks
WEBHOOKS=1

# Enable forum
FORUM=1
</pre>

<h2>
Expose the server to the internet
</h2>

<p>
For simplicity, the server only talks plain HTTP on localhost.
To expose the server to your LAN and/or WAN, either listen to 0.0.0.0 or use a reverse proxy server such as Nginx.
To use SSL (HTTPS) you need a reverse proxy server.

<p>
Here is an example Nginx configuration:

<pre>
server {
	listen 80;
	server_name example.com www.example.com;
	return 301 https://$host$request_uri;
}

server {
	listen 443 ssl;
	server_name example.com www.example.com;
	ssl_certificate /path/to/ssl/certificate/fullchain.cer;
	ssl_certificate_key /path/to/ssl/certificate/example.com.key;
	root /path/to/server/public;
	location / {
		try_files $uri @rally;
	}
	location @rally {
                proxy_pass http://127.0.0.1:8080;
                proxy_http_version 1.1;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_read_timeout 86400s;
                proxy_send_timeout 86400s;
        }
}
</pre>

<h2>
Archive
</h2>

<p>
Storing all the games ever played requires a lot of space. To keep the size of
the main database down, you can delete and/or archive finished games periodically.

<p>
You can copy the game state and replay data for finished games to a separate archive database.
Below are the tools to archive (and restore) the game state data.
Run the archive and purge scripts as part of the backup cron job.

<dl>
<dt>
<code>sqlite3 tools/archive.sql</code>
<dd>
Copy game state data of finished games into archive database.
<dt>
<code>sqlite3 tools/purge.sql</code>
<dd>
Delete game state data of finished games over a certain age.
<dt>
<code>bash tools/unarchive.sh <i>game_id</i></code>
<dd>
Restore archived game state.
</dl>