Safe HaskellNone

IHP.FrameworkConfig

Synopsis

Documentation

newtype AppHostname Source #

Constructors

AppHostname Text 

newtype AppPort Source #

Constructors

AppPort Int 

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

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.

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 <- liftIO $ System.Environment.getEnv "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) }
    

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 #