Setting HANAMI_ENV
allows your code to act differently, depending on the environment.
If HANAMI_ENV
is not set, Hanami will fallback to checking RACK_ENV
. If neither variable is set, the environment defaults to :development
.
By convention, Hanami expects HANAMI_ENV
to be either development
, test
, or production
.
Hanami.env
returns a symbol representing the current environment.
# HANAMI_ENV=test
Hanami.env
=> :test
Hanami.env?
returns true if the given name(s) match the current environment.
# HANAMI_ENV=development
=> true
Hanami.env?(:test)
=> false
Hanami.env?(:production)
=> false
You can match on more than one environment:
# HANAMI_ENV=test
Hanami.env?(:development, :test)
# config/app.rb
module Bookshelf
class App < Hanami::App
environment(:production) do
# Production specific config or initialization
config.middleware.use ProductionOnlyMiddleware
end
end
end
See the for information on supported config options.
When deploying your application to production, set the HANAMI_ENV
environment variable to production
.
In production, Hanami logs to standard out by default, using a structured JSON format with a log level of :info
rather than , which is used in development and test. See the for more detail.