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
- A block ends at a blank line, at the next block, or at the end of the file. A line holding only a comment does not end a block.
#starts a comment at the beginning of a line or after a space, soa#bis one word.- Indentation is ignored.
env:NAMEas a whole argument is replaced by that environment variable.${NAME}works inside an argument, and${NAME:-fallback}supplies a default. A variable that is not set, with no fallback, is an error.- Blocks start in the order written. Put
dataserverfirst, thenlogin, then the servers. - A block may appear more than once (two web servers on two ports, several
appblocks). - Any line JBend does not understand stops the startup with the line number and a description. Nothing starts half-configured.
Top-level lines
| Line | Meaning |
|---|---|
app-id:name | The application's name, shown in the log and in /api/status. |
set name value | A setting for your own code to read with Main.launcher.setting("name", "default"). |
debug 0|1|2 | Extra 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.
| Setting | Meaning |
|---|---|
source dsn | Everything 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 database | Host (optionally host:port) and database name, with the login given by credentials. |
credentials user password | Database login. Quote the password if it contains spaces or #. |
prefix text | Prefix 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.
| Setting | Meaning |
|---|---|
sessions duration | How long a login lasts: 90 (seconds), 30m, 12h, 7d. Default 7d. |
registration open|closed | Whether new accounts can be created. Default open. |
Settings every server block accepts
| Setting | Meaning |
|---|---|
listen port | Required. The port to listen on. |
bind address | Listen 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 n | Simultaneous connections allowed. Default 1000. |
handler class | Your 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.
| Setting | Meaning |
|---|---|
home directory | The directory files are served from. Default res/front/. |
route url file | Serve a file (a path under home) at a URL: route /play /game/play.html. |
routes file | A file of routes to load. Default routes.cfg; a missing file is not an error. |
mount prefix directory | Serve another directory under a URL prefix: mount /docs ../docs. |
upgrade path port | Pass WebSocket handshakes for this path to the WebSocket server or bridge on that local port, so pages use one port for everything. |
set name value | A page variable. {{jbend:name}} in a served HTML, JS or CSS file becomes the value. |
max-body bytes | Largest request body accepted. Default 1048576 (1 MB). |
status on|off | Whether /api/status is served. Default on. |
websocket
A WebSocket server. Without a handler it echoes. See WebSocket server.
| Setting | Meaning |
|---|---|
origin host ... | Only accept connections from pages on these hosts (subdomains included). Without it, any page may connect. |
ping duration | How often idle clients are pinged. Default 25s, which keeps connections alive through proxies. 0 turns pings off. |
idle duration | Close 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.
| Setting | Meaning |
|---|---|
greeting text | Every 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.
| Setting | Meaning |
|---|---|
target host port | Required. The TCP server to relay to. target 9000 alone means this machine. |
mode binary|text | How 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.
| Setting | Meaning |
|---|---|
map host port | Send requests for this host name to this local port. |
default port | Where requests for any other host go. Without it they get a 502. |
backend address | The machine the backends are on. Default 127.0.0.1. |
app
A thread of your own. See Your own thread.
| Setting | Meaning |
|---|---|
class name | Required. A class that implements Runnable (or extends NetApplication) and has a public no-argument constructor. |
name text | The thread's name in the log. Default: the class name. |
set name value | Same as a top-level set; kept next to the class that reads it. |
caretaker and console
| Block | Setting | Meaning |
|---|---|---|
caretaker: | interval duration | How often the caretaker checks the database connection and logs vital signs. Default 5m. |
console: | off | Do 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