Default Lucky environments

Often times your configuration will change based on the environment Lucky is running in.

The default environments in a Lucky app are:

Get the current environment will return the currently running environment

You can also conditionally check the environment with Lucky::Env.test?, Lucky::Env.development?, or Lucky::Env.production?

Set the current environment

LUCKY_ENV=environment_name to set the environment. By default it is development

Configuring Lucky

By default there are some files in the config/ folder that are used to configure Lucky. Look in config/ to configure things like server port, database host and password, etc.

For example, to change the database config, look in config/

Where to put new settings

All application configuration is found in the config/ folder.

If you want to add additional config, put it in a new file in the config/ folder.

Configuring your own code

Lucky ships with Habitat. A module you can use to configure your application in a type safe way. For a thorough look at how to use Habitat, check out the Habitat documentation.

As a quick example, if you had a class for handling payments through Stripe, you may want to include an API token. Here’s how you would do that.

# src/models/
class MyStripeProcessor
  Habitat.create do
    setting api_token : String

Then you can configure it:

# config/
MyStripeProcessor.configure do
  settings.api_token = "super secret"

Using ENV variables for configuration

In reality you would likely want to use an ENV variable for this. To do that, add a .env file to your project root and change your configuration to use the ENV variable:

# .env
# this will be loaded in development when you call `lucky dev`

And in your config file:

# config/
MyStripeProcessor.configure do
  settings.api_token = ENV.fetch("STRIPE_API_TOKEN")

Remember to set the ENV variable in production and you’ll be set!

Next: Setting Up & Migrating the Database