IHP Api Reference
Safe HaskellNone

IHP.FrameworkConfig

Synopsis

Documentation

newtype AppHostname Source #

Constructors

AppHostname Text 

newtype AppPort Source #

Constructors

AppPort Int 

Instances

Instances details
EnvVarReader AppPort Source # 
Instance details

Defined in IHP.FrameworkConfig

newtype BaseUrl Source #

Constructors

BaseUrl Text 

newtype RequestLoggerMiddleware Source #

Provides IHP with a middleware to log requests and responses.

By default this uses the RequestLogger middleware from wai-extra. Take a look at the wai-extra documentation when you want to customize the request logging.

See https://hackage.haskell.org/package/wai-extra-3.0.29.2/docs/Network-Wai-Middleware-RequestLogger.html

Set requestLoggerMiddleware = application -> application to disable request logging.

Constructors

RequestLoggerMiddleware Middleware 

newtype SessionCookie Source #

Provides the default settings for the session cookie.

  • Max Age: 30 days
  • Same Site Policy: Lax
  • HttpOnly (no access through JS)
  • secure, when baseUrl is a https url

Override this to set e.g. a custom max age or change the default same site policy.

Example: Set max age to 90 days > sessionCookie = defaultIHPSessionCookie { Cookie.setCookieMaxAge = Just (fromIntegral (60 * 60 * 24 * 90)) }

Constructors

SessionCookie SetCookie 

newtype DBPoolIdleTime Source #

How long db connection are kept alive inside the connecton pool when they're idle

newtype DBPoolMaxConnections Source #

Max number of db connections the connection pool can open to the database

type ConfigBuilder = StateT TMap IO () Source #

newtype ExceptionTracker Source #

Interface for exception tracking services such as sentry

Constructors

ExceptionTracker 

Fields

newtype IdeBaseUrl Source #

Typically "http://localhost:8001", Url where the IDE is running

Constructors

IdeBaseUrl Text 

newtype RLSAuthenticatedRole Source #

Postgres role to be used for making queries with Row level security enabled

newtype AssetVersion Source #

Constructors

AssetVersion Text 

option :: forall option. Typeable option => option -> StateT TMap IO () Source #

Puts an option into the current configuration

In case an option already exists with the same type, it will not be overriden:

option Production
option Development
findOption @Environment

This code will return Production as the second call to option is ignored to not override the existing option.

env :: forall result monad. MonadIO monad => EnvVarReader result => ByteString -> monad result Source #

Returns a env variable. The raw string value is parsed before returning it. So the return value type depends on what you expect (e.g. can be Text, Int some custom type).

When the parameter is missing or cannot be parsed, an error is raised and the app startup is aborted. Use envOrDefault when you want to get a default value instead of an error, or paramOrNothing to get Nothing when the env variable is missing.

You can define a custom env variable parser by defining a EnvVarReader instance.

Example: Accessing a env var PORT.

Let's say an env var PORT is set to 1337

export PORT=1337

We can read PORT like this:

port <- env @Int "PORT"

Example: Missing env vars

Let's say the PORT env var is not defined. In that case we'll get an error when trying to access it:

>>> port <- env @Int "PORT"
"Env var 'PORT' not set, but it's required for the app to run"

envOrDefault :: MonadIO monad => EnvVarReader result => ByteString -> result -> monad result Source #

envOrNothing :: MonadIO monad => EnvVarReader result => ByteString -> monad (Maybe result) Source #

class EnvVarReader valueType where Source #

findOption :: forall option. Typeable option => StateT TMap IO option Source #

findOptionOrNothing :: forall option. Typeable option => StateT TMap IO (Maybe option) Source #

data FrameworkConfig Source #

Constructors

FrameworkConfig 

Fields

  • appHostname :: !Text
     
  • environment :: !Environment
     
  • appPort :: !Int
     
  • baseUrl :: !Text
     
  • requestLoggerMiddleware :: !Middleware

    Provides IHP with a middleware to log requests and responses.

    By default this uses the RequestLogger middleware from wai-extra. Take a look at the wai-extra documentation when you want to customize the request logging.

    See https://hackage.haskell.org/package/wai-extra-3.0.29.2/docs/Network-Wai-Middleware-RequestLogger.html

    Set requestLoggerMiddleware = application -> application to disable request logging.

  • sessionCookie :: !SetCookie

    Provides the default settings for the session cookie.

    • Max Age: 30 days
    • Same Site Policy: Lax
    • HttpOnly (no access through JS)
    • secure, when baseUrl is a https url

    Override this to set e.g. a custom max age or change the default same site policy.

    Example: Set max age to 90 days > sessionCookie = defaultIHPSessionCookie { Cookie.setCookieMaxAge = Just (fromIntegral (60 * 60 * 24 * 90)) }

  • mailServer :: !MailServer
     
  • databaseUrl :: !ByteString
     
  • dbPoolIdleTime :: !NominalDiffTime

    How long db connection are kept alive inside the connecton pool when they're idle

  • dbPoolMaxConnections :: !Int

    Max number of db connections the connection pool can open to the database

  • cssFramework :: !CSSFramework

    Bootstrap 4 by default

    Override this if you use a CSS framework that is not bootstrap

  • logger :: !Logger
     
  • exceptionTracker :: !ExceptionTracker
     
  • appConfig :: !TMap

    Custom options from Config.hs are stored here

    To access a custom option here, first set it up inside Config.hs. This example reads a string from a env variable on app startup and makes it available to the app by saving it into the application context:

    -- Config.hs:
    
    newtype RedisUrl = RedisUrl String
    
    config :: ConfigBuilder
    config = do
        option Development
        option (AppHostname "localhost")
        
        redisUrl <- env "REDIS_URL"
        option (RedisUrl redisUrl)

    This redis url can be access from all IHP entrypoints using the ?applicationContext that is in scope:

    import qualified Data.TMap as TMap
    import Config -- For accessing the RedisUrl data type
    
    action MyAction = do
        let appConfig = ?context |> getFrameworkConfig |> get #appConfig
        let (RedisUrl redisUrl) = appConfig
                   |> TMap.lookup @RedisUrl
                   |> fromMaybe (error "Could not find RedisUrl in config")
    
  • corsResourcePolicy :: Maybe CorsResourcePolicy

    Configures CORS headers for the application. By default this is set to Nothing, and the server will not respond with any CORS headers

    You can provide a custom CORS policy in Config.hs:

    -- Config.hs
    import qualified Network.Wai.Middleware.Cors as Cors
    
    config :: ConfigBuilder
    config = do
        option Development
        option (AppHostname "localhost")
    
        option Cors.simpleCorsResourcePolicy
    

    Take a look at the documentation of wai-cors https://hackage.haskell.org/package/wai-cors-0.2.7/docs/Network-Wai-Middleware-Cors.html for understanding what simpleCorsResourcePolicy is doing

    You can specify CORS origins like this:

    -- Config.hs
    import qualified Network.Wai.Middleware.Cors as Cors
    
    config :: ConfigBuilder
    config = do
        option Development
        option (AppHostname "localhost")
    
        -- The boolean True specifies if credentials are allowed for the request. You still need to set withCredentials on your XmlHttpRequest
        option Cors.simpleCorsResourcePolicy { Cors.corsOrigins = Just (["localhost"], True) }
    
  • parseRequestBodyOptions :: ParseRequestBodyOptions

    Configures the limits for request parameters, uploaded files, maximum number of headers etc.

    IHP is using parseRequestBodyEx for parsing the HTTP request. By default it applies certain limits to avoid a single request overloading the server.

    You can find the default limits here: https://hackage.haskell.org/package/wai-extra-3.1.6/docs/Network-Wai-Parse.html#v:defaultParseRequestBodyOptions

    You can override the default limits like this:

    -- Config.hs
    import qualified Network.Wai.Parse as WaiParse
    
    config :: ConfigBuilder
    config = do
        option Development
        option (AppHostname "localhost")
    
        -- We extend the default options here
        option $ WaiParse.defaultParseRequestBodyOptions
                |> WaiParse.setMaxRequestNumFiles 20 -- Increase count of allowed files per request
    
  • ideBaseUrl :: Text
     
  • rlsAuthenticatedRole :: Text

    See IHP.DataSync.Role

  • assetVersion :: !Text

    The asset version is used for cache busting

    On IHP Cloud IHP automatically uses the IHP_CLOUD_CONTAINER_ID env variable as the asset version. So when running there, you don't need to do anything.

    If you deploy IHP on your own, you should provide the IHP_ASSET_VERSION env variable with e.g. the git commit hash of the production build.

    If IHP cannot figure out an asset version, it will fallback to the static string "dev".

fromConfig :: (?context :: context, ConfigProvider context) => (FrameworkConfig -> a) -> a Source #

Proxies FrameworkConfig fields contained in some context that can provider a FrameworkConfig

getConfig :: (?context :: context, ConfigProvider context) => FrameworkConfig Source #

Get the current frameworkConfig

defaultIHPSessionCookie :: Text -> SetCookie Source #

Returns the default IHP session cookie configuration. Useful when you want to override the default settings in $sel:sessionCookie:FrameworkConfig

data RootApplication Source #

Constructors

RootApplication 

Instances

Instances details
Eq RootApplication Source # 
Instance details

Defined in IHP.FrameworkConfig

Show RootApplication Source # 
Instance details

Defined in IHP.FrameworkConfig

isEnvironment :: (?context :: context, ConfigProvider context) => Environment -> Bool Source #

isDevelopment :: (?context :: context, ConfigProvider context) => Bool Source #

Returns True when the application is running in Development mode

Development mode means that the Development option is configured in Config/Config.hs

isProduction :: (?context :: context, ConfigProvider context) => Bool Source #

Returns True when the application is running in Production mode

Production mode means that the Production option is configured in Config/Config.hs

defaultCorsResourcePolicy :: Maybe CorsResourcePolicy Source #