Table of Contents
- Settings
Basolato settings are defined in three ways:
- Written in
config.nims
, managed by git, and called at compile time - Defined in
.env
during development or in server environment variables during production, not managed by git, and called at runtime - Recorded in an instance of
Settings.new()
, managed by git, and called at runtime
Changes require recompilation to take effect.
Whether to connect to Sqlite.
Whether to connect to PostgreSQL.
Whether to connect to MySQL.
Whether to connect to MariaDB.
Type of session DB. Either file or redis.
Whether to enable libsaas and allow the use of SASS/SCSS in views.
Sample config.nims
nimCopyputEnv("DB_SQLITE", $true) # "true" or "false"
# putEnv("DB_POSTGRES", $true) # "true" or "false"
# putEnv("DB_MYSQL", $true) # "true" or "false"
# putEnv("DB_MARIADB", $true) # "true" or "false"
putEnv("SESSION_TYPE", "file") # "file" or "redis"
putEnv("USE_LIBSASS", $false) # "true" or "false"
Restart the application to apply changes.
A 100-character key used for encrypting session IDs, etc.
Database name of the target RDB.
Username for connecting to the RDB.
Password for connecting to the RDB.
Host of the target RDB. Specify the absolute file path for Sqlite, or the host
for MySQL and PostgreSQL.
Location of the target RDB. Leave empty for Sqlite, specify the port number
for MySQL and PostgreSQL.
Number of connection pools created for asynchronous RDB connections.
For multi-threaded applications, set this to "maximum connections / number of threads".
Location of the session DB.
Set the absolute file path for file sessions, or host:port
for Redis.
Set the target domains for issuing cookies.
Sample .env
# Secret
SECRET_KEY="GRzV3jfgN8BgFhtiyoLV1aTNE6Evh9r1GLkpBpUCpioXy6ifo10fEL846MTRrd3cpOHMKsYCs1hNQDDYJ3NEOs2mEPYTemU3iGnm"
# DB Connection
DB_DATABASE="database" # sqlite file path or database name
DB_USER="user"
DB_PASSWORD="password"
DB_HOST="127.0.0.1" # host ip address
DB_PORT=5432 # postgres default...5432, mysql default...3306
DB_MAX_CONNECTION=95 # should be smaller than (DB max connection / running num processes)
DB_TIMEOUT=30 # seconds
# Session db
# Session type, file or redis, is defined in config.nims
SESSION_DB_PATH="./session.db" # Session file path or redis host:port. ex:"127.0.0.1:6379"
COOKIE_DOMAINS="" # to specify multiple domains, "sample.com, sample.org"
Non-sensitive information that should be set at runtime but not in environment variables is defined in Settings.new()
.
Hostname of the server to start.
Port number of the server to start.
Set to true to display logs in the terminal, false otherwise.
Set to true to output logs to a file, false otherwise.
Set to true to output error logs to a file, false otherwise.
Absolute path of the log output directory.
Set the session timeout period in minutes.
Set to true to automatically delete the session when the browser is closed.
Language for displaying validation messages.
Language | Environment Variable |
---|---|
English | en |
Japanese | ja |
Sample code main.nim
import basolato
let routs = @[
Route.get("/", example_controller.index)
]
let settings = Settings.new(
host = "127.0.0.1",
port = 8000,
# Logging
logToConsole = true,
logToFile = false,
errorLogToFile = false,
logDir = "./logs",
# Session db
sessionTime = 120, # default 120, minutes of 2 hours
sessionExpireOnClose = false,
# other
locale = "en",
)
serve(routes, settings)