Configuration reference

config/application.conf, config/routes.cfg, config/version.conf

A JBend application is defined by config/application.conf, read once at startup from the directory the program is started in. com.Main contains no application logic at all; change this file and you have a different application.

Syntax

# A comment runs to the end of the line.
app-id:my-app                 # the application's name

debug 1                       # a top-level setting

webserver:                    # a block: a name and a colon, alone on a line
listen 8080                   # a setting: a name, then its arguments
home "my pages"               # quotes keep spaces together

dataserver:                   # the blank line above ended the webserver block
source env:DB_DSN             # the value of the environment variable DB_DSN

Top-level lines

LineMeaning
app-id:nameThe application's name, shown in the log and in /api/status.
set name valueA setting for your own code to read with Main.launcher.setting("name", "default").
debug 0|1|2Extra logging: 1 logs connections opening and closing, 2 also logs every message. Default 0.

dataserver

The connection to MySQL or MariaDB and the thread that runs queries. See Database and queries.

SettingMeaning
source dsnEverything in one string. Either user:password@tcp(host:3306)/database (the Go MySQL driver's format) or mysql://user:password@host:3306/database. Usually source env:DB_DSN, so the password is not in the file.
source host databaseHost (optionally host:port) and database name, with the login given by credentials.
credentials user passwordDatabase login. Quote the password if it contains spaces or #.
prefix textPrefix for the tables JBend creates for itself. Default jbend_, giving jbend_users, jbend_sessions, jbend_bans, so JBend can share a database with another application.

login

Accounts and sessions. Needs a dataserver block before it. See Accounts and sessions.

SettingMeaning
sessions durationHow long a login lasts: 90 (seconds), 30m, 12h, 7d. Default 7d.
registration open|closedWhether new accounts can be created. Default open.

Settings every server block accepts

SettingMeaning
listen portRequired. The port to listen on.
bind addressListen on one address only. bind 127.0.0.1 makes the server reachable from this machine alone, which is what you want behind a reverse proxy. Default: every interface.
max-connections nSimultaneous connections allowed. Default 1000.
handler classYour subclass of the block's protocol (not for bridge or proxy). It needs a public constructor taking (String home, int port) or (int port).

webserver

An HTTP server. See Web server.

SettingMeaning
home directoryThe directory files are served from. Default res/front/.
route url fileServe a file (a path under home) at a URL: route /play /game/play.html.
routes fileA file of routes to load. Default routes.cfg; a missing file is not an error.
mount prefix directoryServe another directory under a URL prefix: mount /docs ../docs.
upgrade path portPass WebSocket handshakes for this path to the WebSocket server or bridge on that local port, so pages use one port for everything.
set name valueA page variable. {{jbend:name}} in a served HTML, JS or CSS file becomes the value.
max-body bytesLargest request body accepted. Default 1048576 (1 MB).
status on|offWhether /api/status is served. Default on.

websocket

A WebSocket server. Without a handler it echoes. See WebSocket server.

SettingMeaning
origin host ...Only accept connections from pages on these hosts (subdomains included). Without it, any page may connect.
ping durationHow often idle clients are pinged. Default 25s, which keeps connections alive through proxies. 0 turns pings off.
idle durationClose clients that have sent no message for this long. Default: never.

tcp

A TCP server. Without a handler it is a line-based echo server. See TCP, bridge and proxy.

SettingMeaning
greeting textEvery client must send this exact line first or be disconnected.

bridge

A WebSocket server that relays each connection to a TCP server, so browsers can reach one. Also accepts origin, ping and idle.

SettingMeaning
target host portRequired. The TCP server to relay to. target 9000 alone means this machine.
mode binary|textHow data from the TCP side is sent to the browser. Default binary.

proxy

A reverse proxy that picks a backend port by the request's Host header.

SettingMeaning
map host portSend requests for this host name to this local port.
default portWhere requests for any other host go. Without it they get a 502.
backend addressThe machine the backends are on. Default 127.0.0.1.

app

A thread of your own. See Your own thread.

SettingMeaning
class nameRequired. A class that implements Runnable (or extends NetApplication) and has a public no-argument constructor.
name textThe thread's name in the log. Default: the class name.
set name valueSame as a top-level set; kept next to the class that reads it.

caretaker and console

BlockSettingMeaning
caretaker:interval durationHow often the caretaker checks the database connection and logs vital signs. Default 5m.
console:offDo not read commands from the terminal. The console is on unless this is given; with no terminal attached it stops by itself.

config/routes.cfg

Routes can also be kept in their own file, one per line. Point the web server at it with routes config/routes.cfg.

# URL on the left, file under the home directory on the right
/login -> /pages/login/login.html
/play  -> /game/play.html

config/version.conf

One line: your application's version. It is shown at startup and in /api/status, and is available as Main.launcher.appVersion(). The file is optional.

1.0.0

A full example

The configuration of the live demo, which runs two games in one process:

app-id:jbend-demo

dataserver:
source env:DB_DSN
prefix jbend_

login:
sessions 7d

webserver:
listen 8090
bind 127.0.0.1
home pages
mount /jbgame build/jbgame
mount /game2018 build/game2018
mount /docs build/docs
upgrade /ws/jbgame 8091
upgrade /ws/game2018 8092
set jbgame-ws ../../../ws/jbgame

websocket:
listen 8091
bind 127.0.0.1
handler com.game.net.GameSocket
origin kanetempleton.com localhost 127.0.0.1
max-connections 150

app:
class com.game.Engine
name JBGame

app:
class server.Embedded
name Game2018

bridge:
listen 8092
bind 127.0.0.1
target 127.0.0.1 10018
origin kanetempleton.com localhost 127.0.0.1

caretaker:
interval 30m