Safe Haskell | Safe-Inferred |
---|
IHP.FrameworkConfig
Synopsis
- newtype AppHostname = AppHostname Text
- newtype AppPort = AppPort Int
- newtype BaseUrl = BaseUrl Text
- newtype RequestLoggerMiddleware = RequestLoggerMiddleware Middleware
- newtype SessionCookie = SessionCookie SetCookie
- newtype DBPoolIdleTime = DBPoolIdleTime NominalDiffTime
- newtype DBPoolMaxConnections = DBPoolMaxConnections Int
- newtype DatabaseUrl = DatabaseUrl ByteString
- type ConfigBuilder = StateT TMap IO ()
- newtype ExceptionTracker = ExceptionTracker {
- onException :: Maybe Request -> SomeException -> IO ()
- newtype IdeBaseUrl = IdeBaseUrl Text
- newtype RLSAuthenticatedRole = RLSAuthenticatedRole Text
- newtype AssetVersion = AssetVersion Text
- newtype CustomMiddleware = CustomMiddleware Middleware
- newtype DataSyncMaxSubscriptionsPerConnection = DataSyncMaxSubscriptionsPerConnection Int
- newtype DataSyncMaxTransactionsPerConnection = DataSyncMaxTransactionsPerConnection Int
- option :: forall option. Typeable option => option -> StateT TMap IO ()
- ihpDefaultConfig :: ConfigBuilder
- env :: forall result monad. MonadIO monad => EnvVarReader result => ByteString -> monad result
- envOrDefault :: MonadIO monad => EnvVarReader result => ByteString -> result -> monad result
- envOrNothing :: MonadIO monad => EnvVarReader result => ByteString -> monad (Maybe result)
- class EnvVarReader valueType where
- envStringToValue :: ByteString -> Either Text valueType
- initAssetVersion :: ConfigBuilder
- findOption :: forall option. Typeable option => StateT TMap IO option
- findOptionOrNothing :: forall option. Typeable option => StateT TMap IO (Maybe option)
- buildFrameworkConfig :: ConfigBuilder -> IO FrameworkConfig
- data FrameworkConfig = FrameworkConfig {
- appHostname :: !Text
- environment :: !Environment
- appPort :: !Int
- baseUrl :: !Text
- requestLoggerMiddleware :: !Middleware
- sessionCookie :: !SetCookie
- mailServer :: !MailServer
- databaseUrl :: !ByteString
- dbPoolIdleTime :: !NominalDiffTime
- dbPoolMaxConnections :: !Int
- cssFramework :: !CSSFramework
- logger :: !Logger
- exceptionTracker :: !ExceptionTracker
- appConfig :: !TMap
- corsResourcePolicy :: Maybe CorsResourcePolicy
- parseRequestBodyOptions :: ParseRequestBodyOptions
- ideBaseUrl :: Text
- rlsAuthenticatedRole :: Text
- assetVersion :: !Text
- customMiddleware :: !CustomMiddleware
- type ConfigProvider context = HasField "frameworkConfig" context FrameworkConfig
- defaultIHPSessionCookie :: Text -> SetCookie
- data RootApplication = RootApplication
- defaultPort :: Int
- defaultDatabaseUrl :: HasCallStack => IO ByteString
- defaultLoggerForEnv :: HasCallStack => Environment -> IO Logger
- isEnvironment :: (?context :: context, ConfigProvider context) => Environment -> Bool
- isDevelopment :: (?context :: context, ConfigProvider context) => Bool
- isProduction :: (?context :: context, ConfigProvider context) => Bool
- defaultCorsResourcePolicy :: Maybe CorsResourcePolicy
- withFrameworkConfig :: ConfigBuilder -> (FrameworkConfig -> IO result) -> IO result
- initModelContext :: FrameworkConfig -> IO ModelContext
- data ExceptionWithCallStack = ExceptionWithCallStack CallStack SomeException
- configIO :: (MonadIO monad, HasCallStack) => IO result -> monad result
Documentation
newtype AppHostname Source #
Constructors
AppHostname Text |
Instances
EnvVarReader AppPort Source # | |
Defined in IHP.FrameworkConfig Methods envStringToValue :: ByteString -> Either Text AppPort Source # |
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.
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
Constructors
DBPoolIdleTime NominalDiffTime |
newtype DBPoolMaxConnections Source #
Max number of db connections the connection pool can open to the database
Constructors
DBPoolMaxConnections Int |
newtype DatabaseUrl Source #
Constructors
DatabaseUrl ByteString |
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
Constructors
RLSAuthenticatedRole Text |
newtype AssetVersion Source #
Constructors
AssetVersion Text |
newtype CustomMiddleware Source #
Constructors
CustomMiddleware Middleware |
newtype DataSyncMaxSubscriptionsPerConnection Source #
Constructors
DataSyncMaxSubscriptionsPerConnection Int |
newtype DataSyncMaxTransactionsPerConnection Source #
Constructors
DataSyncMaxTransactionsPerConnection Int |
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 #
Methods
envStringToValue :: ByteString -> Either Text valueType Source #
Instances
EnvVarReader ByteString Source # | |
Defined in IHP.FrameworkConfig Methods envStringToValue :: ByteString -> Either Text ByteString Source # | |
EnvVarReader Environment Source # | |
Defined in IHP.FrameworkConfig Methods envStringToValue :: ByteString -> Either Text Environment Source # | |
EnvVarReader AppPort Source # | |
Defined in IHP.FrameworkConfig Methods envStringToValue :: ByteString -> Either Text AppPort Source # | |
EnvVarReader Text Source # | |
Defined in IHP.FrameworkConfig Methods envStringToValue :: ByteString -> Either Text Text Source # | |
EnvVarReader IPAddrSource Source # | |
Defined in IHP.FrameworkConfig Methods envStringToValue :: ByteString -> Either Text IPAddrSource Source # | |
EnvVarReader String Source # | |
Defined in IHP.FrameworkConfig Methods envStringToValue :: ByteString -> Either Text String Source # | |
EnvVarReader Int Source # | |
Defined in IHP.FrameworkConfig Methods envStringToValue :: ByteString -> Either Text Int Source # |
data FrameworkConfig Source #
Constructors
FrameworkConfig | |
Fields
|
Instances
HasField "frameworkConfig" ControllerContext FrameworkConfig Source # | |
Defined in IHP.Controller.Context Methods | |
HasField "frameworkConfig" FrameworkConfig FrameworkConfig Source # | |
Defined in IHP.FrameworkConfig Methods |
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
Show RootApplication Source # | |
Defined in IHP.FrameworkConfig Methods showsPrec :: Int -> RootApplication -> ShowS # show :: RootApplication -> String showList :: [RootApplication] -> ShowS # | |
Eq RootApplication Source # | |
Defined in IHP.FrameworkConfig Methods (==) :: RootApplication -> RootApplication -> Bool # (/=) :: RootApplication -> RootApplication -> Bool # |
defaultPort :: Int Source #
defaultLoggerForEnv :: HasCallStack => Environment -> IO Logger Source #
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
data ExceptionWithCallStack Source #
Wraps an Exception thrown during the config process, but adds a CallStack
Inspired by https://maksbotan.github.io/posts/2021-01-20-callstacks.html
Constructors
ExceptionWithCallStack CallStack SomeException |
Instances
Exception ExceptionWithCallStack Source # | |
Defined in IHP.FrameworkConfig | |
Show ExceptionWithCallStack Source # | |
Defined in IHP.FrameworkConfig Methods showsPrec :: Int -> ExceptionWithCallStack -> ShowS # show :: ExceptionWithCallStack -> String showList :: [ExceptionWithCallStack] -> ShowS # |
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.