Skip to content

[mode]

[mode] sets whether an application starts in production mode or in development mode.

The block has two keys. default is the mode that an application starts in. ceiling is the highest mode that code may select, and development is higher than production. When ceiling is not set, it is the same as default. Then code cannot switch to a higher mode than the one the application started in. The mode gives the defaults of the logger and of the HTTP error pages.

A program reads the mode with Core\Config::get("mode.default"). Core\Config::set("mode.default", "development") changes the mode for the current request. It returns true when ceiling allows development, and false when it does not. Only nvs.toml sets ceiling. The compiler checks a name written as text in the call, so Core\Config::set("mode.ceiling", …) does not compile.

Good to know: the name to read is mode.default. Core\Config::get("mode") returns null, and Core\Config::set("mode", …) does not compile.

Examples

The examples below run with this configuration file.

nvs.toml
# Every request starts in production mode.
# A program may switch its own request to development mode, and no further.
[mode]
default = "production"
ceiling = "development"

Switch one request to development

<?nvs
// Shows how a program reads the mode from `[mode]` and switches its own request to development mode.
// `mode.default` is the mode the request starts in. This prints `production`.
echo Core\Config::get('mode.default'), "\n";
// `mode.ceiling` is the most permissive mode a program may choose. This prints `development`.
echo Core\Config::get('mode.ceiling'), "\n";
// "development" is within the ceiling, so the call returns `true`. This prints `yes` and `development`.
echo Core\Config::set('mode.default', 'development') ? 'yes' : 'no', "\n";
echo Core\Config::get('mode.default'), "\n";
// Only the person who runs the server may change the ceiling.
// `Core\Config::set('mode.ceiling', ...)` does not compile,
// because a program may not change `mode.ceiling`.
// This program keeps the name in a variable. The compiler does not check a variable, so `set` runs and returns `false`.
// This prints `no`.
string $ceiling = 'mode.ceiling';
echo Core\Config::set($ceiling, 'production') ? 'yes' : 'no', "\n";
Output
production
development
yes
development
no

mode.default

The mode this host runs in.

Novis has two modes and no third: production, and development, which trades the safe defaults away for the detail a developer wants. This key is where that choice is written, and where a program reads it back. Written nowhere it is production — a deployment that forgets the line is the safe one, and the developer who wants the other one asks for it once.

The mode is a shorthand, not a switch: it changes the default of five ordinary directives — how logs are formatted, how much of them is kept, whether requests are logged, how much of an error a caller sees, and whether a dump is printed inline. Each of those is still spellable on its own line, so a mode beside an explicit value means what it reads like.

A program may flip its own mode, as far as [mode] ceiling allows. A name that is neither mode is refused; staging is a production host with different configuration, which is what staging has always been.

The example reads the mode, branches on it the way an application does, and is turned away asking for a third one.

nvs.toml sets the value that each request starts with. A request may change its own value with Core\Config::set, up to the ceiling where the key has one.

A change in the file takes effect a few seconds after you save it. The server does not restart.

Which mode this host is running in

<?nvs
// `[mode] default` is the mode the server runs in. It is `production` unless the
// configuration says otherwise. A program reads it for things like demo data
// or a debug page.
echo 'running in: ', Core\Env::mode() == Core\Env::Mode::Development ? 'development' : 'production', "\n";
// This configuration does not set the mode, so `Core\Config::get` returns the
// default, `production`.
echo 'in force: ', Core\Config::get('mode.default') ?? '(no value)', "\n";
// `Core\Env::mode()` returns the current mode, so this runs the `else` branch.
if (Core\Env::mode() == Core\Env::Mode::Development) {
echo 'seeding the demo account', "\n";
} else {
echo 'not seeding: real orders live on this host', "\n";
}
// There are only two modes. `staging` is not one of them, so the call returns
// `false`. A staging server runs in `production` with its own settings.
echo 'select staging: ', Core\Config::set('mode.default', 'staging') ? 'accepted' : 'refused', "\n";
// The mode sets the default of five other settings. You can still change each
// of them on its own, like `log.level` here.
echo 'ask for debug logs: ', Core\Config::set('log.level', 'debug') ? 'accepted' : 'refused', "\n";
echo 'log level is now: ', Core\Config::get('log.level') ?? '(no value)', "\n";
Output
running in: production
in force: production
not seeding: real orders live on this host
select staging: refused
ask for debug logs: accepted
log level is now: debug

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

mode.ceiling

The most permissive mode any code on this host may select.

Novis has two modes and no third: production, which a host runs in unless something says otherwise, and development, which trades the safe defaults away for the detail a developer wants. A program may flip its own mode — one application on a shared host can need the other one — and this key says how far that flip may go.

Written nowhere it equals the mode the host started in. A production machine is then unreachable from development mode with nothing configured at all, and a developer who started their server in development mode flips freely without writing anything either; only a host running both kinds of application at once needs the line.

Past the ceiling the flip answers false and leaves the mode where it was. Raising the ceiling itself is the operator's alone, because a program that could raise it could grant itself the mode it had just been refused.

The example flips in both directions and shows which of the two calls is turned away.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

How far a program may flip its own mode

<?nvs
// `[mode] ceiling` is the highest mode any code on this server may select.
// `development` allows more than `production`, so `development` is the higher mode.
// A program may change its own mode, but not past the ceiling.
// This file does not write a ceiling, so the ceiling is the mode the server started in.
// This prints `production` twice.
echo 'running in: ', Core\Env::mode() == Core\Env::Mode::Development ? 'development' : 'production', "\n";
echo 'ceiling: ', Core\Config::get('mode.ceiling') ?? '(no value)', "\n";
// `production` is at the ceiling, so this call returns `true`.
echo 'select production: ', Core\Config::set('mode.default', 'production') ? 'accepted' : 'not allowed', "\n";
// `development` is above the ceiling, so the call returns `false`. The server
// started in production, and the mode stays `production`.
echo 'select development: ', Core\Config::set('mode.default', 'development') ? 'accepted' : 'not allowed', "\n";
echo 'still running in: ', Core\Env::mode() == Core\Env::Mode::Development ? 'development' : 'production', "\n";
// Only the person who runs the server may change the ceiling.
// `Core\Config::set('mode.ceiling', ...)` does not compile,
// because a program may not change `mode.ceiling`.
// This program keeps the name in a variable. The compiler does not check a variable, so `set` runs and returns `false`.
string $ceiling = 'mode.ceiling';
echo 'raise the ceiling: ', Core\Config::set($ceiling, 'development') ? 'accepted' : 'not allowed', "\n";
Output
running in: production
ceiling: production
select production: accepted
select development: not allowed
still running in: production
raise the ceiling: not allowed

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.