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

Safe Haskell | None
Language | Haskell2010

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 Source #

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

Constructors

Development |
Testing |
Staging |
Production |

#### Instances

Instances details

Bounded DefaultEnv Source # |
Instance details Defined in Yesod.Default.Config Methods minBound :: DefaultEnv Source # maxBound :: DefaultEnv Source #
Enum DefaultEnv Source # |

Instance details

Defined in Yesod.Default.Config

Methods

succ :: DefaultEnv -> DefaultEnv Source #

pred :: DefaultEnv -> DefaultEnv Source #

toEnum :: Int -> DefaultEnv Source #

fromEnum :: DefaultEnv -> Int Source #

enumFrom :: DefaultEnv -> [DefaultEnv] Source #

enumFromThen :: DefaultEnv -> DefaultEnv -> [DefaultEnv] Source #

enumFromTo :: DefaultEnv -> DefaultEnv -> [DefaultEnv] Source #

enumFromThenTo :: DefaultEnv -> DefaultEnv -> DefaultEnv -> [DefaultEnv] Source #

Read DefaultEnv Source # |
Instance details Defined in Yesod.Default.Config Methods readsPrec :: Int -> ReadS DefaultEnv Source # readList :: ReadS [DefaultEnv] Source # readPrec :: ReadPrec DefaultEnv Source # readListPrec :: ReadPrec [DefaultEnv] Source #
Show DefaultEnv Source # |
Instance details Defined in Yesod.Default.Config Methods showsPrec :: Int -> DefaultEnv -> ShowS Source # show :: DefaultEnv -> String Source # showList :: [DefaultEnv] -> ShowS Source #

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

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) Source #

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

Since 1.2.2

loadDevelopmentConfig :: IO (AppConfig DefaultEnv ()) Source #

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

data AppConfig environment extra Source #

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

Instances details

(Show environment, Show extra) => Show (AppConfig environment extra) Source # |
Instance details Defined in Yesod.Default.Config Methods showsPrec :: Int -> AppConfig environment extra -> ShowS Source # show :: AppConfig environment extra -> String Source # showList :: [AppConfig environment extra] -> ShowS Source #

data ConfigSettings environment extra Source #

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 () Source #

Default config settings.

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

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 Source #

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`.