Configuration
Azu provides a flexible, environment-aware configuration system that lets you tailor your application for development, testing, and production. This guide covers all major configuration options, best practices, and real-world examples.
1. The configure Block
configure BlockAzu applications are configured using a configure block inside your main application module:
module MyApp
include Azu
configure do
# Configuration options go here
port = ENV.fetch("PORT", "4000").to_i
host = ENV.fetch("HOST", "0.0.0.0")
template_hot_reload = env.development?
end
endAll configuration is available at compile time, ensuring type safety and performance.
2. Server Settings
host: The IP address or hostname to bind the server (default:0.0.0.0)port: The port to listen on (default:4000)port_reuse: Allow port reuse (default:false)
3. SSL/TLS Configuration
For production, enable HTTPS with SSL certificates:
If both ssl_cert and ssl_key are set, Azu will start in TLS mode.
4. Template Engine
templates.path: Array of directories to search for templatestemplate_hot_reload: Enable hot reloading in developmenttemplates.error_path: Directory for error templates
5. File Uploads
upload.max_file_size: Maximum allowed file size (default:10.megabytes)upload.temp_dir: Directory for temporary file uploadsupload.allowed_extensions: Restrict allowed file extensionsupload.allowed_mime_types: Restrict allowed MIME types
6. Logging
log.level: Set log verbosity (DEBUG,INFO,WARN,ERROR)log: Use a custom logger if needed
7. Environment Detection
Azu automatically detects the environment:
Azu::CONFIG.env.development?Azu::CONFIG.env.production?Azu::CONFIG.env.test?
You can set the environment via the AZU_ENV environment variable:
Or programmatically:
8. Middleware Stack
Configure the order and presence of middleware in your application:
Order matters: place error handlers and loggers early, static/file handlers later.
9. Advanced: Custom Configuration
You can add your own configuration options by extending the configure block:
Access your custom config via Azu::CONFIG or your module's config method.
10. Best Practices
Use environment variables for secrets and environment-specific values
Enable hot reload only in development
Restrict file uploads in production
Set log level to
INFOor higher in productionDocument all custom configuration
Keep configuration in one place for maintainability
Example: Production vs. Development
Troubleshooting Configuration
Wrong port/host? Check environment variables and
configureblock.Templates not reloading? Ensure
template_hot_reload = truein development.File uploads failing? Check
upload.max_file_sizeand permissions.Logging too verbose? Set
log.levelappropriately.SSL not working? Ensure both
ssl_certandssl_keyare set and readable.
Further Reading
Azu's configuration system is designed for clarity, safety, and flexibility. Use it to build robust, environment-aware applications with confidence.
Last updated
Was this helpful?
