Yesod.Default.Config

yesod-1.4.2: Creation of type-safe, RESTful web applications.

Safe Haskell | None
Language | Haskell98

Yesod.Default.Config

Synopsis

- data DefaultEnv
  - = Development
  - | Testing
  - | Staging
  - | Production
- fromArgs :: (Read env, Show env, Enum env, Bounded env) => (env -> Object -> Parser extra) -> IO (AppConfig env extra)
- fromArgsSettings :: (Read env, Show env, Enum env, Bounded env) => (env -> IO (ConfigSettings env extra)) -> IO (AppConfig env extra)
- loadDevelopmentConfig :: IO (AppConfig DefaultEnv ())
- data AppConfig environment extra = AppConfig {
  - appEnv :: environment
  - appPort :: Int
  - appRoot :: Text
  - appHost :: HostPreference
  - appExtra :: extra
  }
- data ConfigSettings environment extra = ConfigSettings {
  - csEnv :: environment
  - csParseExtra :: environment -> Object -> Parser extra
  - csFile :: environment -> IO FilePath
  - csGetObject :: environment -> Value -> IO Value
  }
- configSettings :: Show env => env -> ConfigSettings env ()
- loadConfig :: ConfigSettings environment extra -> IO (AppConfig environment extra)
- withYamlEnvironment :: Show e => FilePath -> e -> (Value -> Parser a) -> IO a

# Documentation

data DefaultEnv

A yesod-provided ``AppEnv``, allows for Development, Testing, and Production environments

Constructors

Development |
Testing |
Staging |
Production |

Instances

Bounded DefaultEnv |
Enum DefaultEnv |
Read DefaultEnv |
Show DefaultEnv |

fromArgs :: (Read env, Show env, Enum env, Bounded env) => (env -> Object -> Parser extra) -> IO (AppConfig env extra)

Load the app config from command line parameters

fromArgsSettings :: (Read env, Show env, Enum env, Bounded env) => (env -> IO (ConfigSettings env extra)) -> IO (AppConfig env extra)

Load the app config from command line parameters, using the given @ConfigSettings.

Since 1.2.2

loadDevelopmentConfig :: IO (AppConfig DefaultEnv ())

Load your development config (when using ``DefaultEnv``)

data AppConfig environment extra

Dynamic per-environment configuration which can be loaded at run-time negating the need to recompile between environments.

Constructors

AppConfig |
Fields appEnv :: environment appPort :: Int appRoot :: Text appHost :: HostPreference appExtra :: extra

Instances

(Show environment, Show extra) => Show (AppConfig environment extra) |

data ConfigSettings environment extra

Constructors

ConfigSettings |
Fields csEnv :: environment An arbitrary value, used below, to indicate the current running environment. Usually, you will use `DefaultEnv` for this type. csParseExtra :: environment -> Object -> Parser extra Load any extra data, to be used by the application. csFile :: environment -> IO FilePath Return the path to the YAML config file. csGetObject :: environment -> Value -> IO Value Get the sub-object (if relevant) from the given YAML source which contains the specific settings for the current environment.

configSettings :: Show env => env -> ConfigSettings env ()

Default config settings.

loadConfig :: ConfigSettings environment extra -> IO (AppConfig environment extra)

Load an ``AppConfig``.

Some examples:

    -- typical local development
    Development:
      host: localhost
      port: 3000

      -- approot: will default to ""

    -- typical outward-facing production box
    Production:
      host: www.example.com

      -- port: will default 80
      -- host: will default to "*"
      -- approot: will default "http://www.example.com"

    -- maybe you're reverse proxying connections to the running app
    -- on some other port
    Production:
      port: 8080
      approot: "http://example.com"
      host: "localhost"

withYamlEnvironment

Arguments

:: Show e |
=> FilePath | the yaml file
-> e | the environment you want to load
-> (Value -> Parser a) | what to do with the mapping
-> IO a |

Loads the configuration block in the passed file named by the passed environment, yields to the passed function as a mapping.

Errors in the case of a bad load or if your function returns `Nothing`.