Configuration

Azu configuration properties are minimal this is to help you keep everything in a mental model without overloading your brain.

Overview

Azu configuration properties are minimal this is to help you keep everything in a mental model without overloading your brain.

/my_app/src/my_app.cr
require "azu"

module MyApp
  include Azu
  
  VERSION = "0.1.0"
  
  configure do
    port = 4000
    host = localhost
    port_reuse = true
    log = Log.for("My Awesome App")
    env = Environment::Development
    template.path = "./templates"
    template.error_path = "./error_template"
  end
end

# Starts the HTTP Server
MyApp.start [
  Azu::Handler::Rescuer.new,
  Azu::Handler::Logger.new,
]

Configuration properties lives within your application's main file.

Configuration Properties

Apps sometimes store config as constants in the code. This is a violation of the twelve-factor, which requires strict separation of config from code. Config varies substantially across deploys, code does not.

Azu follows the https://12factor.net/config standards this is why Azu first attempts to load configuration values from the environment first if not found then it loads from code.

We recommend for development use .env files.

  1. .env file

  2. .env.local file

  3. .env.#{CRYSTAL_ENV} file

  4. .env.#{CRYSTAL_ENV}.local file

Important: Azu does NOT load the .env files automatically. It is up to you the developer to use your preferred method to load environment variables.

Example

export CRYSTAL_ENV=development 
export CRYSTAL_LOG_SOURCES="*" 
export CRYSTAL_LOG_LEVEL=info 
export CRYSTAL_WORKERS=8 
export PORT=4000 
export PORT_REUSE=true 
export HOST=0.0.0.0

App Environments

By default Azu ships with the following environments:

  • Build

  • Development

  • Test

  • Integration

  • Acceptance

  • Pipeline

  • Staging

  • Production

The current application environment is determined via the CRYSTAL_ENV variable.

Use the following method to determine or compare environments

MyApp.env 
# => Production
MyApp.env.production?
# => true
MyApp.env == Environment::Development
# => false
MyApp.env.in? :development
# => false

Middlewares

Finally, you must know how to start the server.

MyApp.start [
  Azu::Handler::Rescuer.new,
  Azu::Handler::Logger.new,
]

Last updated