pub struct Config {Show 31 fields
pub listen: SocketAddr,
pub handler_script: PathBuf,
pub config_script: Option<PathBuf>,
pub database: Option<DatabaseConfig>,
pub workers: usize,
pub max_streams: Option<usize>,
pub dev_mode: bool,
pub std: StdConfig,
pub trust_request_id: bool,
pub limits: LimitsConfig,
pub rate_limit: RateLimitConfig,
pub fetch: FetchConfig,
pub shutdown: ShutdownConfig,
pub compression: CompressionConfig,
pub cors: CorsConfig,
pub headers: BTreeMap<String, String>,
pub tls: TlsConfig,
pub cache: CacheConfig,
pub static_files: StaticConfig,
pub templating: TemplatingConfig,
pub multipart: MultipartConfig,
pub cookies: CookiesConfig,
pub testing: TestingConfig,
pub env: EnvConfig,
pub lua: LuaConfig,
pub health: HealthConfig,
pub static_dirs_optional: bool,
pub openapi: OpenApiConfig,
pub swagger: SwaggerConfig,
pub log: LogConfig,
pub pidfile: Option<PathBuf>,
}Expand description
Server configuration, typically loaded from a nitr.toml file.
Precedence (strongest first): CLI flags / builder setters, NITR_*
environment variables (see apply_env()), the TOML
file, and finally the built-in defaults.
Fields§
§listen: SocketAddrAddress the server binds to.
handler_script: PathBufThe handler script, loaded once per Lua state at startup and on every reload; its routes serve the requests.
config_script: Option<PathBuf>Lua script executed once at startup; its returned table is passed to the handler on every request.
database: Option<DatabaseConfig>SQLite database for the db builtin ([database] section): the
file path plus the connection pragmas.
workers: usizeNumber of pooled Lua states (the maximum concurrently executing) handlers.
max_streams: Option<usize>Maximum concurrent streaming responses (each holds a pooled state
for its whole lifetime). Defaults to workers - 1, so idle streams
cannot pin the entire pool; with one worker that is still 1, and
startup warns that one stream then holds the only state.
dev_mode: boolDevelopment mode: hot-reload the handler script on change.
std: StdConfigStandard library (nitr.*) selection ([std] section). When the
feature list is omitted, only the minimal set is enabled; an
explicit list is strict and fails at startup when a listed feature
is missing its configuration (e.g. template without
[templating] dir).
trust_request_id: boolTrust an inbound X-Request-ID header (well-formed, <= 64 ASCII
chars) instead of generating a fresh id. Enable only behind a proxy
that sets or sanitizes the header.
limits: LimitsConfigRequest-size and connection limits ([limits] section).
rate_limit: RateLimitConfigPer-client rate limiting ([rate_limit] section).
fetch: FetchConfigOutbound-request policy for the fetch builtin ([fetch] section).
shutdown: ShutdownConfigGraceful-shutdown timing ([shutdown] section).
compression: CompressionConfigResponse compression ([compression] section).
cors: CorsConfigCross-origin resource sharing ([cors] section).
headers: BTreeMap<String, String>Headers added to every response ([headers] section): the static
files, the built-in rejections and the SPA page included. A header
the handler itself set wins.
tls: TlsConfigInbound TLS termination ([tls] section).
cache: CacheConfigThe shared nitr.cache ([cache] section).
static_files: StaticConfigStatic file serving ([static] section).
templating: TemplatingConfigTemplate rendering ([templating] section).
multipart: MultipartConfigFilesystem policy for multipart uploads ([multipart] section).
Cookie defaults ([cookies] section).
testing: TestingConfigTest runner settings ([testing] section).
env: EnvConfigEnvironment access for the nitr.env builtin ([env] section).
lua: LuaConfigLua runtime settings.
health: HealthConfigHealth and readiness endpoints ([health] section).
static_dirs_optional: boolSet by a tool that proves the application without serving it
(nitr check, nitr test): a static directory that does not exist
yet is skipped with a warning rather than refused, because the
front-end build that fills it runs later. Never read from a file.
openapi: OpenApiConfigThe generated OpenAPI document ([openapi] section).
swagger: SwaggerConfigThe Swagger UI page ([swagger] section).
log: LogConfigLog output ([log] section).
pidfile: Option<PathBuf>File the server writes its process id to at startup (and removes at
exit), so nitr reload and scripts can find the process without
grepping the process table.
Implementations§
Source§impl Config
impl Config
Sourcepub fn load_env_file(&self, base: &Path) -> Result
pub fn load_env_file(&self, base: &Path) -> Result
Loads the configured dotenv-style file into the process environment.
Called between from_file() and
apply_env(); base is the directory relative
paths resolve against (where nitr.toml lives, or the working
directory for a bundle — the env file is external state, like the
database). Precedence: NITR_ENV_FILE names the file outright (it
can only come from the real environment), else [env] file from
the TOML, else an implicit .env under base that may be absent —
only an explicitly named file must exist. Loading never
overwrites variables already present in the process environment.
Sourcepub fn apply_env(&mut self) -> Result
pub fn apply_env(&mut self) -> Result
Applies NITR_* environment variable overrides on top of the
current values.
Top-level keys keep their plain names: NITR_LISTEN,
NITR_HANDLER_SCRIPT, NITR_CONFIG_SCRIPT, NITR_WORKERS,
NITR_MAX_STREAMS, NITR_DEV_MODE, NITR_PIDFILE,
NITR_TRUST_REQUEST_ID. A sectioned
option is named NITR_<SECTION>_<OPTION>: NITR_DATABASE_PATH,
NITR_TEMPLATING_DIR, NITR_TESTING_DIR, NITR_TESTING_DATABASE,
NITR_ENV_FILE, NITR_LUA_MEMORY_LIMIT,
NITR_LUA_EXEC_TIMEOUT_MS, NITR_LIMITS_POOL_WAIT_MS,
NITR_SHUTDOWN_GRACE, NITR_COMPRESSION_ENABLED,
NITR_TLS_ENABLED, NITR_TLS_CERT, NITR_TLS_KEY,
NITR_TLS_MIN_VERSION, NITR_LOG_FORMAT, NITR_LOG_LEVEL,
NITR_OPENAPI_ENABLED, NITR_OPENAPI_PATH, NITR_SWAGGER_ENABLED,
NITR_SWAGGER_PATH, NITR_COOKIES_SECURE,
NITR_RATE_LIMIT_TRUST_FORWARDED_FOR.
Source§impl Config
impl Config
Sourcepub fn rebase(&mut self, root: &Path)
pub fn rebase(&mut self, root: &Path)
Re-anchors the application’s relative paths under root.
Used when running from a nitr build bundle: the scripts, templates
and static files live in the extraction directory, while the
database path is deliberately left alone, it is mutable state and
stays external to the artifact, resolving against the working
directory as usual. [multipart] upload_dir is left alone for the
same reason — uploads outlive the bundle they were received by, and
re-anchoring them inside a nitr build extraction directory would
make them vanish on the next deploy. [tls] cert/key are left
alone for the stronger version of the same reason: a private key
inside a copyable one-file artifact is a private key that leaks
with it.
Sourcepub fn validate_testing(&self) -> Result
pub fn validate_testing(&self) -> Result
What nitr test checks on top of the boot validation: its tests
directory becomes a second require root in test states, so it
gets the rule the handler’s directory has — an upload root inside
it would make an uploaded .lua file a loadable module.
Sourcepub fn effective_toml(&self) -> Result<String>
pub fn effective_toml(&self) -> Result<String>
The effective configuration after file, environment, and flag layering, rendered as TOML, the answer to “which value actually won?”.
Source§impl Config
impl Config
Sourcepub fn env_options(&self) -> EnvOptions
pub fn env_options(&self) -> EnvOptions
The read policy handed to the nitr.env builtin.
Why a cookie built without Secure deserves a warning, for the
first such cookie to log. "auto" cannot see a proxy terminating
TLS in front of a plaintext bind, the most common deployment, so
it says so once a cookie actually ships that way; dev_mode and an
explicit "never" are the operator’s answer and stay silent.
Sourcepub fn cache_options(&self) -> CacheOptions
pub fn cache_options(&self) -> CacheOptions
Limits for the shared nitr.cache.
Sourcepub fn builtins(&self) -> Result<Builtins>
pub fn builtins(&self) -> Result<Builtins>
Resolves the configured [std] features list into Builtins flags.
With no explicit list, the minimal default set
(Builtins::minimal(): json, http, log, time,
validate, base64, path, url) is enabled to keep the
standard library lightweight. An explicit list is strict:
unknown names or a listed feature without its required setting fail
here.
Sourcepub fn runtime_opts(&self) -> Result<RuntimeOpts>
pub fn runtime_opts(&self) -> Result<RuntimeOpts>
Builds the RuntimeOpts derived from this configuration.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more