Skip to content

Application Configuration

Sword uses thisconfig to load one or more TOML files.

By default, ApplicationBuilder loads config/config.toml during initialization. If the file is missing or contains invalid TOML, application build fails.

If you need a different path, you can build the application with:

  • Application::from_config(...).
  • Application::from_config_path(...).

[application] section

This section contains general application-level values:

KeyTypeDefaultDescription
nameOption<String>NoneApplication name
environmentOption<String>NoneEnvironment name
graceful-shutdownboolfalseEnables graceful shutdown when termination signals are received
TOML example
toml
[application]
name = "My Sword App"
environment = "development"
graceful-shutdown = true

Runtime-specific configuration

As shown in Application Types, Sword supports two runtime types: Web and gRPC. Each one has its own section.

[web] configuration

This applies to web applications and web extensions such as socketio.

KeyTypeDefaultDescription
hostString"0.0.0.0"Bind host or IP for the web application
portu168000Web application port
router-prefixOption<String>NoneGlobal prefix for web routes
request-timeoutOption<RequestTimeoutConfig>NoneTimeout configuration for web controllers
body-limitOption<BodyLimitConfig>10MBBody size limit configuration for web request extraction
TOML example
toml
[web]
host = "0.0.0.0"
port = 8000
router-prefix = "/api"
body-limit = "2MB"
request-timeout = { enabled = true, timeout = "30s" }

[socketio] configuration

In Sword, socketio is a web extension. So when you use it, you configure the web runtime first and then add the dedicated Socket.IO section.

KeyTypeDefaultDescription
ack-timeoutOption<TimeConfig>5sMaximum time for outgoing ACKs
connect-timeoutOption<TimeConfig>45sTime limit to complete initial connection
max-buffer-sizeOption<usize>128Max buffered packets per connection
max-payloadOption<ByteConfig>100KBMaximum outgoing payload size
ping-intervalOption<TimeConfig>25sServer ping interval
ping-timeoutOption<TimeConfig>20sPong timeout before disconnect
req-pathOption<String>"/socket.io"HTTP path where Socket.IO is mounted
transportsOption<Vec<String>>["polling", "websocket"]Allowed transports
parser"common" | "msgpack""common"Payload parser
ws-read-buffer-sizeOption<usize>4096WebSocket read buffer size
TOML example
toml
[socketio]
ack-timeout = "5s"
connect-timeout = "45s"
max-buffer-size = 128
max-payload = "100KB"
ping-interval = "25s"
ping-timeout = "20s"
req-path = "/socket.io"
transports = ["polling", "websocket"]
parser = "common"
ws-read-buffer-size = 4096

[grpc] configuration

This section applies to gRPC applications and is unrelated to the web runtime.

KeyTypeDefaultDescription
hostString"0.0.0.0"Bind host or IP for the gRPC server
portu1650051gRPC server port
enable-tonic-reflectionboolfalseEnables tonic reflection service
body-limitOption<GrpcBodyLimitConfig>10MBSize limit config for incoming/outgoing gRPC messages
TOML example
toml
[grpc]
host = "0.0.0.0"
port = 50051
enable-tonic-reflection = true
body-limit = { max-decoding-message-size = "4MB", max-encoding-message-size = "4MB" }