bring comments back in
This commit is contained in:
parent
6de7a5e9d1
commit
2d0d70fd60
@ -23,13 +23,41 @@ data AppEnvironment = Development
|
|||||||
| Production
|
| Production
|
||||||
deriving (Eq, Show, Read, Enum, Bounded)
|
deriving (Eq, Show, Read, Enum, Bounded)
|
||||||
|
|
||||||
|
-- | Dynamic per-environment configuration which can be loaded at
|
||||||
|
-- run-time negating the need to recompile between environments.
|
||||||
data AppConfig = AppConfig
|
data AppConfig = AppConfig
|
||||||
{ appEnv :: AppEnvironment
|
{ appEnv :: AppEnvironment
|
||||||
, appPort :: Int
|
, appPort :: Int
|
||||||
|
|
||||||
|
-- | Your application will keep a connection pool and take
|
||||||
|
-- connections from there as necessary instead of continually
|
||||||
|
-- creating new connections. This value gives the maximum number
|
||||||
|
-- of connections to be open at a given time. If your application
|
||||||
|
-- requests a connection when all connections are in use, that
|
||||||
|
-- request will fail. Try to choose a number that will work well
|
||||||
|
-- with the system resources available to you while providing
|
||||||
|
-- enough connections for your expected load.
|
||||||
|
--
|
||||||
|
-- Connections are returned to the pool as quickly as possible by
|
||||||
|
-- Yesod to avoid resource exhaustion. A connection is only
|
||||||
|
-- considered in use while within a call to runDB.
|
||||||
, connectionPoolSize :: Int
|
, connectionPoolSize :: Int
|
||||||
, appRoot :: Text
|
|
||||||
|
-- | The base URL for your application. This will usually be
|
||||||
|
-- different for development and production. Yesod automatically
|
||||||
|
-- constructs URLs for you, so this value must be accurate to
|
||||||
|
-- create valid links.
|
||||||
|
--
|
||||||
|
-- If your domain name was "yesod.com", you would probably want it
|
||||||
|
-- to be:
|
||||||
|
--
|
||||||
|
-- > "http://yesod.com"
|
||||||
|
--
|
||||||
|
, appRoot :: Text
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
|
-- | Load an @'AppConfig'@ from a YAML-formatted file located at
|
||||||
|
-- @config\/settings.yml@.
|
||||||
loadConfig :: AppEnvironment -> IO AppConfig
|
loadConfig :: AppEnvironment -> IO AppConfig
|
||||||
loadConfig env = do
|
loadConfig env = do
|
||||||
allSettings <- (join $ YAML.decodeFile ("config/settings.yml" :: String)) >>= fromMapping
|
allSettings <- (join $ YAML.decodeFile ("config/settings.yml" :: String)) >>= fromMapping
|
||||||
@ -51,6 +79,8 @@ loadConfig env = do
|
|||||||
Production -> ""
|
Production -> ""
|
||||||
_ -> ":" ++ show p
|
_ -> ":" ++ show p
|
||||||
|
|
||||||
|
-- | Load Postgresql settings from a YAML-formatted file located at
|
||||||
|
-- @config\/postgresql.yml@.
|
||||||
loadPostgresqlConnStr :: AppEnvironment -> IO Text
|
loadPostgresqlConnStr :: AppEnvironment -> IO Text
|
||||||
loadPostgresqlConnStr env = do
|
loadPostgresqlConnStr env = do
|
||||||
allSettings <- (join $ YAML.decodeFile ("config/postgresql.yml" :: String)) >>= fromMapping
|
allSettings <- (join $ YAML.decodeFile ("config/postgresql.yml" :: String)) >>= fromMapping
|
||||||
@ -62,13 +92,16 @@ loadPostgresqlConnStr env = do
|
|||||||
return $ [st| #{key}=#{value} |]
|
return $ [st| #{key}=#{value} |]
|
||||||
return $ [st|#{connPart} dbname=#{database}|]
|
return $ [st|#{connPart} dbname=#{database}|]
|
||||||
|
|
||||||
|
-- | Load Sqlite settings from a YAML-formatted file located at
|
||||||
|
-- @config\/sqlite.yml@.
|
||||||
loadSqliteConnStr :: AppEnvironment -> IO Text
|
loadSqliteConnStr :: AppEnvironment -> IO Text
|
||||||
loadSqliteConnStr env = do
|
loadSqliteConnStr env = do
|
||||||
allSettings <- (join $ YAML.decodeFile ("config/sqlite.yml" :: String)) >>= fromMapping
|
allSettings <- (join $ YAML.decodeFile ("config/sqlite.yml" :: String)) >>= fromMapping
|
||||||
settings <- lookupMapping (show env) allSettings
|
settings <- lookupMapping (show env) allSettings
|
||||||
lookupScalar "database" settings
|
lookupScalar "database" settings
|
||||||
|
|
||||||
-- note: no type signature to avoid Persistent.MongoDB dep
|
-- note: no type signature to avoid an extra Persistent.MongoDB dep for
|
||||||
|
-- those that don't need it
|
||||||
--loadMongoConnParams :: AppEnvironment -> IO (Database, HostName)
|
--loadMongoConnParams :: AppEnvironment -> IO (Database, HostName)
|
||||||
loadMongoConnParams env = do
|
loadMongoConnParams env = do
|
||||||
allSettings <- (join $ YAML.decodeFile ("config/mongoDB.yml" :: String)) >>= fromMapping
|
allSettings <- (join $ YAML.decodeFile ("config/mongoDB.yml" :: String)) >>= fromMapping
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user