IHP Api Reference
Safe HaskellSafe-Inferred

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 

newtype CustomMiddleware Source #

Constructors

CustomMiddleware Middleware 

newtype Initializer Source #

Constructors

Initializer 

Fields

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.

addInitializer :: ((?context :: FrameworkConfig, ?modelContext :: ModelContext) => IO ()) -> StateT TMap IO () Source #

Adds a callback to be run during startup of the app server

The follwoing example will print a hello world message on startup:

config = do
    addInitializer (putStrLn "Hello World!")

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

    Used by the dev server. This field cannot be strict.

  • rlsAuthenticatedRole :: !Text

    See IHP.DataSync.Role

  • assetVersion :: !Text

    The asset version is used for cache busting

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

  • customMiddleware :: !CustomMiddleware

    User provided WAI middleware that is run after IHP's middleware stack.

  • initializers :: ![Initializer]
     

Instances

Instances details
HasField "frameworkConfig" ControllerContext FrameworkConfig Source # 
Instance details

Defined in IHP.Controller.Context

HasField "frameworkConfig" FrameworkConfig FrameworkConfig Source # 
Instance details

Defined in IHP.FrameworkConfig

type ConfigProvider context = HasField "frameworkConfig" context FrameworkConfig Source #

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
Show RootApplication Source # 
Instance details

Defined in IHP.FrameworkConfig

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

withFrameworkConfig :: ConfigBuilder -> (FrameworkConfig -> IO result) -> IO result Source #

Builds a config and calls the provided callback.

Once the callback has returned the resources allocated by the config are closed. Specifcally this will close open log file handles.

Example:

import Config (config)

withFrameworkConfig config \frameworkConfig -> do
    -- Do something with the FrameworkConfig here

configIO :: (MonadIO monad, HasCallStack) => IO result -> monad result Source #

Runs IO inside the config process

It works like liftIO, but attaches a CallStack on error. Without this it would be hard to see where an error during the config setup comes from.

All call-sites of this function should also have a HasCallStack constraint to provide helpful information in the call stack.

See https://github.com/digitallyinduced/ihp/issues/1503

Orphan instances

EnvVarReader IPAddrSource Source # 
Instance details

Methods

envStringToValue :: ByteString -> Either Text IPAddrSource Source #