You can configure various aspects of your Hanami app using config in your app class.

  1. # config/app.rb
  2. module Bookshelf
  3. class App < Hanami::App
  4. config.inflections do |inflections|
  5. inflections.acronym "WNBA"
  6. end
  7. end
  8. end

You can also configure your app differently in different environments.

  1. # config/app.rb
  2. module Bookshelf
  3. class App < Hanami::App
  4. environment(:production) do
  5. require "my_custom_middleware"
  6. config.middleware.use MyCustomMiddleware
  7. end
  8. end
  9. end

See the environments guide for more detail.

Individual slices may also be configured. See the slices guide for more detail.

See below for a description of all available config methods.

General

inflections

Along with inflector, customizes your your app’s string inflection rules. See the inflector guide for more detail.

slices

Specifies the slices to load. See the slices guide for more detail.

Code loading

root

Sets the root for the app or slice. For the app, defaults to Dir.pwd. For slices, defaults to the slice’s name under the /slices/ directory.

The root is used for locating the code to be loaded by the app. See the autoloading guide and the containers and components guide for more detail.

shared_app_component_keys

Sets the keys for the app components to be automatically imported into each slice. See the slices guide for more detail.

no_auto_register_paths

Sets an array of paths (relative to the root of the app or any slice) to be excluded from component auto-registration. Defaults to ["entities"]. See the containers and components guide for more detail.

Router

base_url

Sets the base URL for the app’s web server. This is used when building URLs for named routes. Defaults to "http://0.0.0.0:2300". See the routes guide for more detail.

middleware

Configures the Rack middleware stack to be used by the app’s router. Defaults to an empty middleware stack.

Add a middleware with use:

  1. # config/app.rb
  2. config.middleware.use MyMiddleware, "middleware", "args", "here"

Use the before: or after: options to insert a middleware at a particular point in the stack:

  1. # config/app.rb
  2. config.middleware.use MyMiddleware, before: AlreadyAddedMiddleware

If you configure actions to use the :json format, then Hanami::Middleware::BodyParser will be added automatically and configured to parse JSON request bodies.

Actions

Sets the configuration to be used by all actions in the app.

  1. # config/app.rb
  2. config.actions.format :json

See the actions guide for more detail.