Skip to main content

Config

Struct Config 

Source
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: SocketAddr

Address the server binds to.

§handler_script: PathBuf

The 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: usize

Number 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: bool

Development mode: hot-reload the handler script on change.

§std: StdConfig

Standard 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: bool

Trust 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: LimitsConfig

Request-size and connection limits ([limits] section).

§rate_limit: RateLimitConfig

Per-client rate limiting ([rate_limit] section).

§fetch: FetchConfig

Outbound-request policy for the fetch builtin ([fetch] section).

§shutdown: ShutdownConfig

Graceful-shutdown timing ([shutdown] section).

§compression: CompressionConfig

Response compression ([compression] section).

§cors: CorsConfig

Cross-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: TlsConfig

Inbound TLS termination ([tls] section).

§cache: CacheConfig

The shared nitr.cache ([cache] section).

§static_files: StaticConfig

Static file serving ([static] section).

§templating: TemplatingConfig

Template rendering ([templating] section).

§multipart: MultipartConfig

Filesystem policy for multipart uploads ([multipart] section).

§cookies: CookiesConfig

Cookie defaults ([cookies] section).

§testing: TestingConfig

Test runner settings ([testing] section).

§env: EnvConfig

Environment access for the nitr.env builtin ([env] section).

§lua: LuaConfig

Lua runtime settings.

§health: HealthConfig

Health and readiness endpoints ([health] section).

§static_dirs_optional: bool

Set 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: OpenApiConfig

The generated OpenAPI document ([openapi] section).

§swagger: SwaggerConfig

The Swagger UI page ([swagger] section).

§log: LogConfig

Log 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

Source

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.

Source

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

Source

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.

Source

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.

Source

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

Source

pub fn from_file(path: &Path) -> Result<Self>

Loads the configuration from a TOML file.

Source

pub fn env_options(&self) -> EnvOptions

The read policy handed to the nitr.env builtin.

Source

pub fn cookie_insecure_warning(&self) -> Option<String>

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.

Source

pub fn cache_options(&self) -> CacheOptions

Limits for the shared nitr.cache.

Source

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.

Source

pub fn runtime_opts(&self) -> Result<RuntimeOpts>

Builds the RuntimeOpts derived from this configuration.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config
where Config: Default,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more